I'm not sure why this my android_clean data set as 5 extra entries

Screen Link:
https://app.dataquest.io/c/112/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/5/removing-duplicate-entries-part-two

My Code:

android_clean = []
already_added = []
for i in googleplay_data[1:]:
    if (i[0] in reviews_max) and (reviews_max[i[0]]==float(i[3])):
        if i[0] not in already_added:
            android_clean.append(i)
    else:
        already_added.append(i[0])

What I expected to happen:
I tried doing it a different way from what was guided in the instructions, but expected it to produce the same result.

What actually happened:
But 5 extra entries appeared and I’m not sure why.

Replace this line with the output/error

The advice I would like to get is

  1. Which part of my above code caused the problem?
  2. How do I go about figuring where the 5 extra entries are? I suppose if I knew the answer to 1, I would be able to figure this out.

[quote=“adn.goh, post:1, topic:556176”]

    if i[0] not in already_added:
        android_clean.append(i)
else:
    already_added.append(i[0])

The if condition looks at if i[0] is not in already_added. If it’s not you append to android_clean. And if it’s not then that’s when you should be appending to already_added as well.

But, you end up appending to already_added when it’s already part of it. So, after a while, already_added will have duplicates in it which is not what we need.

1 Like