Seperate list of 'Non-English Data'

Mission link:Learn data science with Python and R projects

To work on this mission, I found the result of my code comes out totally different from the the solution notebook. However I think these two codes are exactly same except the list name.

This is the is_english function code before these 2 sets of code:

def is_english(string):
non_ascii = 0

for character in string:
    if ord(character) > 127:
        non_ascii += 1
if non_ascii > 3:
    return False
else:
    return True

print(is_english(‘Docs To Go™ Free Office Suite’))
print(is_english(‘Instachat :stuck_out_tongue_winking_eye:’))
print(is_english(‘爱奇艺PPS -《欢乐颂2》电视剧热播’))

This is my code:

English_ios=
English_android=

for app in ios:
name=app[1]
if is_english(name):
English_ios.append(name)

for app in android_clean:
name=app[0]
if is_english(name):
English_android.append(name)

explore_data(English_ios, 0,3, True)
print(’\n’)
explore_data(English_android, 0,3, True)

I consider them exactly same as the solution code: (which from solutions/Mission350Solutions.ipynb at master · dataquestio/solutions · GitHub)

android_english =
ios_english =

for app in android_clean:
name = app[0]
if is_english(name):
android_english.append(app)

for app in ios:
name = app[1]
if is_english(name):
ios_english.append(app)

explore_data(android_english, 0, 3, True)
print(’\n’)
explore_data(ios_english, 0, 3, True)

In the future, can you please include the output so that others can see the differences that you are talking about. It would save people a lot of time and therefore increase the chances that someone can answer your question more easily/quickly.

After I recreated your code to see the differences in the outputs, I was able to see where the code is different. Specifically these few lines:
(Your code)

for app in ios:
    name=app[1]
    if is_english(name):
        English_ios.append(name)

Compared to the solution code:

for app in ios:
    name = app[1]
    if is_english(name):
        ios_english.append(app)

One difference I see is that inside the if condition in your code, you are appending the variable name to the list English_ios whereas in the solution code we are appending app to the list ios_english. The names of the lists aren’t important but can you see how these append statements are fundamentally different? Let me know if you need any more clarification and we can try some more exploring.

1 Like

Hi mathmike314,

You always give me a good explanation of my questions, which is so helpful!

Appreciate it deeply!

Yuming

Thank you for your kind words. Honestly, it’s my pleasure and I hope I get the chance to help you again in the future.

Happy coding!