Guided Project page 7/14

https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/7/removing-non-english-apps-part-two

the solution is:

non_ascii = 0    
for character in string:
    if ord(character) > 127:
        non_ascii += 1

if non_ascii > 3:
    return False
else:
    return True

I get the global logic but I’m unclear about the way we re defining non_ascii here

Hello @gaelle.c,

Your question is a little vague but I will attempt to answer it to my own interpretation. I am not sure of what you mean by the way we are defining non_ascii here but let me add this:

The non_ascii integer variable is initialized with the value 0 and it is incremented by a value of 1 non_ascii += 1 each time the corresponding number for a character in the string value is greater than 127.

Such that when the value of the non_ascii is greater than 3 (which means that there are more than 3 characters in the input string that fall outside the ASCII range: 0-127), it returns False but returns True otherwise.

I hope this helps.

@gaelle.c,

Another approach to solving this problem is

def is_english(string):
    non_ascii = []
    for character in string:
        if ord(character) > 127:
            non_ascii.append(character)
            
    if len(non_ascii) > 3:
        return False
    else:
        return True

In this case, you append the characters in the input string whose corresponding value fall outside the ASCII range to the non_ascii list.
If the length of the non_ascii list is greater than 3, you return False to show that it is a Non-English App.

hey @gaelle.c

like @doyinsolamiolaoye even I am unclear about your query. So this is my interpretation.

take for example these three dummy apps:

  • dummy appTM
  • dummy app :slight_smile:
  • dummy :u7981: :u7533: :u5408: :u6708: :u6708: app

in the first two apps we have two proper English words and one non-English word/ symbol etc. (TM here is a subscript). We don’t want to exclude apps like these from the apps list.

using this code non_ascii > 3 we are trying to put a cap as to how many invalid characters/ symbols, non-English words etc. are allowed in an app name so that it can be included in the apps list.

In this case, the third app won’t be included because there are 5 non-English words.

If the app name was something like this “dummy :u7981: :u7533: :u5408: app” it would have been included in the app list, because we are taking up to 3 non-ASCII characters in an app name.

In case neither answer helped you, please provide more details to your query.

Thank you both for your answers, I understand better now.

2 Likes

It’s my pleasure.
Happy learning!