Guided Project: Profitable App Profiles for the App Store and Google Play Markets Question

Screen Link: Learn data science with Python and R projects

So in the second guided project, I am stuck understanding the loop example for detecting duplicate entries for the Googleplay Store.

The code that was given:

duplicate_apps =

for app in android:
if name in unique apps:

  1. How can we loop through unique apps if it is an empty list?
  2. How can we assign duplicate rows to duplicate_apps from unique_apps if unique_apps is an empty list?
    3)I’m assuming that if the app is not already in unique_apps we append unique_apps and feed them the unique rows. Again, how can we do this if unique_apps is an empty list?

Thanks for your help, I guess I am just really confused on how we are checking to see if rows in unique_apps are duplicate when it has not been assigned anything. How can you perform if name in unique apps, above we created it as an empty list?

1 Like

Hello @rfarivar74 ,
Firstly, it is better to present code snippets using the preformatted text button “</>” in the toolbar.
If I understand the code you tried pasting to be

duplicate_apps = []     
unique_apps = []

for app in android:
    name = app[0]
    if name in unique_apps:

The explanation is this:
Lines 1 and 2 >>> initialize empty lists(variables) because you want to find duplicate and unique apps in the android dataset and put them in different places(variables).

Lines 3 >>>This is the Loop and it is looping(going) through the android dataset to search for duplicate and unique apps which is like going through the whole android records row by row from the first row/record.
Lines 4 >>> extracting the name of the app in each row using index function because the names of the apps are located as first items.
Lines 5 , 6, 7, 8>>> This is NOT a loop but a Condition. If the name of the app in the current row is already in the unique_apps list, then add it to the duplicate_apps list, but, if it is not already in the unique_apps list, then add it to unique_apps.

That is to say, the loop is on the android dataset which is NOT empty and NOT on the duplicate_apps and uniques_apps lists that are empty as initialized.
Hope this answers your question.


Hi @rfarivar74 ,

Great questions!

Remember you are looping through the android list to extract the name of each app then checking if the name is in the unique_apps list like @Ezemonye_Omereji explained.

For example: android[ ] list has thousands of rows. Remember you are looping through android [ ] list with the for loop:
for app in android

So lets pretend on your first loop, the name is “Earthquake App 1.0”.
name = app[0] replacing name = android[0]
name = “Earthquake App 1.0”

Now you go to the if statement to determine if the value in the name variable “Earthquake App 1.0” is in the unique_apps [ ] list
if name in unique_apps:
Since this is the first loop, the unique_apps list is empty so no “Earthquake App 1.0” is not in the unique_apps list. So the else statement kicks in and append “Earthquake App 1.0” to unique_apps list.
** unique_apps.append(name)**

Before we go to the second loop of the ** for app in android** loop lets check the two lists
unique_apps list has one item “Earthquake App 1.0”
duplicate_apps list is still empty

Now let’s go to the second loop
for app in android:

So on the second loop lets pretend the name is “Earthquake App 1.0” again.
So now the if statement checks whether name “Earthquake App 1.0” is in unique_app [ ] list. Yes, it is in the unique_apps list so go to next line and append “Earthquake App 1.0” to duplicate_apps [ ] because it is a duplicate since “Earthquake App 1.0” was already appended in the first loop.

The following logic repeats until every row is looped through in the android [ ] list

  1. you extract the name ** name = app[0]**
  2. use if statement to check whether the value in the name variable is in unique_apps if name in unique_apps
  3. if the name is already in the unique_apps list then you append the name to the duplicate_apps list duplicate_apps.append(name)
  4. if the name is not in the unique_apps list then you append the name to the unique_apps list

wow, thank you so much! I appreciate you taking me through each iteration and explaining everything that was going on.


thanks for the help and for the tip! this helped me conceptualize it well

1 Like