DS 1. project, "string index out of range"

I get aforementioned error when trying to append the free apps from both lists. I suspect it might be for not converting to float when dealing with elements such as “3M” in price/cost. But I am not sure.

``
android_free =
ios_free =

for app in android_english:
cost = app[7]
if cost == ‘0’:
android_free = app

for app in ios_english:
cost = app[4]
if cost == ‘0’:
ios_free = ios_clean

print(len(android_free))
print(len(android_clean))
´´
The code:
1.App_analysis.ipynb (8.8 KB)

Click here to view the jupyter notebook file in a new tab

Your notebook has a similar issue to this post: IndexError: string index out of range? The issue pops up in the way that the english-only datasets for android and ios are created.

Also, once you fix that, you’ll want to be careful with this part here:

for app in android_english: 
    cost = app[7]
    if cost == '0':
        android_free = app

I think what you want to do here is append the row to the new android_free list, but instead it’s going to replace the whole list with just a single row for every iteration.

Hope that helps!

1 Like

Aha yes, I actually changed it to append before posting, alas same errors occures.
at “cost = app[7]” an error is returned with “string index out of range”

android_free = []
ios_free = []

for app in android_english: 
    cost = app[7]
    if cost == '0':
        android_free.append(app)

Did you go back to the previous cell and fix the error there and rerun it?

This section of code generates a list of just the app names.

android_english = []
ios_english = [] 

for app in android_clean: 
    name = app[0]
    if is_english(name):
        android_english.append(name)    #app name appended, not entire row
        
for app in ios_clean:
    name = app[2]
    if is_english(name):
        ios_english.append(name)     #app name appended, not entire row

This is what the android_english list looks like from the above code:

android_english[:5]

['Photo Editor & Candy Camera & Grid & ScrapBook',
 'U Launcher Lite – FREE Live Cool Themes, Hide Apps',
 'Sketch - Draw & Paint',
 'Pixel Draw - Number Art Coloring Book',
 'Paper flowers instructions']

The string index out of range error comes about because for app in android_english: treats each string as a list of characters. So app[7] on the first iteration for example is the 8th character of Photo Editor & Candy Camera & Grid & ScrapBook, or 'd'. There are app names that are less than 8 characters, so when we try to access app[7], you get a string index out of range error because app[7] doesn’t exist.

Once I changed the above section of code I didn’t get that error anymore.

As a side note and heads up, you’re going to come up with another problem here:

for app in ios_english: 
    cost = app[4]
    if cost == '0':        # hint: inspect the way free app prices are written in the ios set
        ios_free.append(app)
1 Like

Hey thanks for the help so far. I see what you are saying, and made som corrections.
Also, helped to revise the code in the solution ipynb.