A logic issue using python

Screen Link:

My Code:

unique_installs = []
repeated_installs = []

for value in android_free[1:]:
    install = value[5]
    install = install.replace(',', '')
    
    substring = '+'
    if install.find(substring): 
        install = install.replace('+', '')
        install = int(install)
        install +=1
        
    if install in unique_installs:
        repeated_installs.append(install)
    else:
        unique_installs.append(install)
        
sorted(unique_installs, reverse = True)

What I expected to happen:

[1000000001,
1000000000
 500000001,
500000000
 100000001,
100000000
 50000001,
50000000
 10000001,
10000000
 5000001,
5000000
 1000001,
1000000
 500001,
500000
 100001,
100000
 50001,
50000
 10001,
10000
 5001,
5000
 1001,
1000
 501,
500
 101,
100
 51,
50
 11,
10,
6,
5,
2,
1,
 0]

What actually happened:

[1000000001,
 500000001,
 100000001,
 50000001,
 10000001,
 5000001,
 1000001,
 500001,
 100001,
 50001,
 10001,
 5001,
 1001,
 501,
 101,
 51,
 11,
 6,
 2,
 1]
1 Like

Every value - which is the number of installs - in the list of lists has the ‘+’ sign in it, so the if clause gets executed every time the loop runs and all the values will be incremented by 1. So, there would be no value which will end with 0 and return the sequence which you are expecting.

Hi, yes, exactly.
But there is another if clause inside, that was supposed to consider only the strings that have +, for the + and +=1.
I am talking about the column installs in this dataset.

Then, all the strings have + symbol in it, and each one of them gets replaced by an empty character and gets converted to an int and gets incremented by 1, right?

2 Likes

You got it. Except for the 0, all of them have +. Thanks! :slight_smile:

1 Like