How to remove english alphabets from list in python

I have a list with some English text and another in Hindi . I want to remove all items from a list written in English. How to do it?

An example . How to remove hello from the list L below?

 L = ['рдореИрд╕реЗрдЬ','рдЦреЗрд▓рдирд╛','рджрд╛рд░рд╛','hello','рдореБрджреНрд░рдг'] for i in range(len(L)): print L[i] 

Expected Result:

 рдореИрд╕реЗрдЬ рдЦреЗрд▓рдирд╛ рджрд╛рд░рд╛ рдореБрджреНрд░рдг 
+6
source share
4 answers

You can use the isalpha() function

 l = ['рдореИрд╕реЗрдЬ', 'рдЦреЗрд▓рдирд╛', 'рджрд╛рд░рд╛', 'hello', 'рдореБрджреНрд░рдг'] for word in l: if not word.isalpha(): print word 

will give you the result:

 рдореИрд╕реЗрдЬ рдЦреЗрд▓рдирд╛ рджрд╛рд░рд╛ рдореБрджреНрд░рдг 
+7
source

How about a simple list comprehension:

 >>> import re >>> i = ['рдореИрд╕реЗрдЬ','рдЦреЗрд▓рдирд╛','рджрд╛рд░рд╛','hello','рдореБрджреНрд░рдг'] >>> [w for w in i if not re.match(r'[AZ]+', w, re.I)] ['рдореИрд╕реЗрдЬ', 'рдЦреЗрд▓рдирд╛', 'рджрд╛рд░рд╛', 'рдореБрджреНрд░рдг'] 
+2
source

You can use filter with match regular expression:

 import re list(filter(lambda w: not re.match(r'[a-zA-Z]+', w), ['рдореИрд╕реЗрдЬ','рдЦреЗрд▓рдирд╛','рджрд╛рд░рд╛','hello','рдореБрджреНрд░рдг'])) 
+1
source

You can use the Python regex module.

 import re l=['рдореИрд╕реЗрдЬ','рдЦреЗрд▓рдирд╛','рджрд╛рд░рд╛','hello','рдореБрджреНрд░рдг'] for string in l: if not re.search(r'[a-zA-Z]', string): print(string) 
0
source

All Articles