Screen Link:
Can anyone explain why my codes not work to get unique apps and duplicate apps? I used count() function.
My Code: <
unique_apps =[]
dup_apps =[]
for row in android_data:
for ele in row:
name = row[0]
if row.count(name) > 1:
dup_apps.append(name)
else:
unique_apps.append(name)
print(len(dup_apps))
print(dup_apps[:15])>
The output is:
52
[‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Weather’, ‘Comics’, ‘Comics’]
@czha001 I certainly hope you are enjoying your learning. Keep up the good work.
From my understanding, I do not see the reason of looping twice >> for ele in row
-
You have identified the empty lists required properly. Great!
unique_apps =
dup_apps =
-
Next you have looped over your data set. Cool!
for row in android_data:
-
remember we are using app name here as a unique id. Therefore, we need to identify its index in the row and assign it to a variable “name”
name = row[0]
- Try and think of it this way: unique_apps list should be filled with name only once, otherwise it is a duplicate.
you could use the code below:
if name in unique_apps:
duplicate_apps.append(name)
else:
unique_apps.append(name)
Note: Ofcourse consider the syntax
The rest you should be able to complete.
Thanks and happy learning.
1 Like