Did not understand name=app[0] in the code? Could anyone explain how it works?

uplicate_apps = []
unique_apps = []

for android_app in android:
    name = android_app[0]
    if name in unique_apps:
print('Duplicate apps:', len(duplicate_apps))
print('Unique apps:',len(unique_apps))
print('Examples of duplicate apps:', duplicate_apps[:15])

What I expected to happen:
I did not understand why we need to write name=i[0] and how it works

1 Like

Hello @handepehlivan1 welcome to the community.

android_header, contains a list of the column names. If you use indexing to see the item on position 0, android_header[0], it is App, which is the name of the app.

Similarly, when you take the same index position on andriod, you are referring to the name of the app. andriod is a list containing lists, so when I take the first list and take the item on the first position on the list, andriod[0][0], the name of the app is Photo Editor & ...


name = android_app[0] means assigned the name of the app to the variable name.
if name in unique_apps checks if it is in the list unique_apps. If it is indeed in unique_apps, append the name of this app to duplicate_apps. Else append it to unique_apps (because the name of this app was not found in the list of unique_apps so it is not a duplicate).

Please check out these guidelines for asking good questions.


Firstly, thank you for your reply. So I understand name = android_app[0] take the index position on android
. Throughout the code is it go to the 1,2… , n position in android ?
if it is, is it only store 1 element in the android app, so they call android_app[0]?

What the code here intends to do is check if an app was stored more than one times on the list. So you do so with the name of the app. You iterate over the rows and check if the name of the app is unique or not.

You iterate over the list of list with for android_app in android.

For every new list called andriod_app, take the first position, index 0, and assign what you find ther to the variable name. So the name changes for every iteration. You check this name against your unique_apps list each time to find out if it is already in the list: if name in unique_apps

This is one list:
alist = ['A', 10, 3.5']. alist[0] = A
This is a list of list:
[['A', 10, 3.5], ['B', 5, 2.5], ['C', 2, 1.3]]

You move like this:

andriod_app = ['A', 10, 3.5]  and assign name = andriod_app[0] = 'A'
andriod_app = ['B', 5, 2.5]  and assign name =andriod_app[0] =  'B'
andriod_app = ['C', 2, 1.3] and assign name = andriod_app[0] = 'C'