Issue when using len() function

Hi everyone!

So I am trying to understand what’s happening in my code. I am analyzing the Apple and Google Play app store data. What I decided to do is check each list and count the number of entries (columns) in that list. When looking at google app data, the header is composed of 13 columns. I assumed that all other rows will have 13 columns as well. However, when checked each row, some are tagged having more, less or equal to 13. NOT what I expected.

I am pretty sure I am missing something simple here. Please help!

less_than13=[]
equal_13=[]
more_than13=[]
index=0

for each in google:

    if len(each[0])<13:
        less_than13.append(each)

    elif len(each[0])==13:
        equal_13.append(each)
        
    elif len(each[0])>13:
        more_than13.append(each)
        
print(len(less_than13))
print(len(equal_13))
print(len(more_than13))

When I run this code:

print(equal_13[0])
print('\n')
print(less_than13[0])
print('\n')
print(more_than13[0])

I get:
[‘Paint Splash!’, ‘ART_AND_DESIGN’, ‘3.8’, ‘2206’, ‘1.2M’, ‘100,000+’, ‘Free’, ‘0’, ‘Everyone’, ‘Art & Design;Creativity’, ‘April 15, 2018’, ‘1.46’, ‘4.1 and up’]

[‘ibis Paint X’, ‘ART_AND_DESIGN’, ‘4.6’, ‘224399’, ‘31M’, ‘10,000,000+’, ‘Free’, ‘0’, ‘Everyone’, ‘Art & Design’, ‘July 30, 2018’, ‘5.5.4’, ‘4.1 and up’]

[‘Photo Editor & Candy Camera & Grid & ScrapBook’, ‘ART_AND_DESIGN’, ‘4.1’, ‘159’, ‘19M’, ‘10,000+’, ‘Free’, ‘0’, ‘Everyone’, ‘Art & Design’, ‘January 7, 2018’, ‘1.0.0’, ‘4.0.3 and up’]

However, all of these lists have 13 columns exactly. Not sure why they are being tagged as having something else than 13!

Hi @ruslan02000,

You should remove [0] from everywhere in your loop, then you will get the correct result.

You have a list of lists google and you want to check the length of each list in it. But now in your code you have practically checked the length of Paint Splash! (whicn is equal to 13), ibis Paint X (<13) and Photo Editor & Candy Camera & Grid & ScrapBook (>13).

OK that makes total sense now!!! By using [index] I can check length of each entry. Thank you.

1 Like