Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove english alphabets from list in python

I have a list with some English text while other in Hindi. I want to remove all elements from list written in English. How to achieve that?

Example: How to remove hello from list L below?

L = ['मैसेज','खेलना','दारा','hello','मुद्रण']  

for i in range(len(L)):    
    print L[i]

Expected Output:

मैसेज    
खेलना    
दारा    
मुद्रण
like image 535
Ishpreet Avatar asked Jul 19 '16 05:07

Ishpreet


2 Answers

You can use isalpha() function

l = ['मैसेज', 'खेलना', 'दारा', 'hello', 'मुद्रण']
for word in l:
    if not word.isalpha():
        print word

will give you the result:

मैसेज
खेलना
दारा
मुद्रण
like image 75
aroy Avatar answered Sep 23 '22 21:09

aroy


How about a simple list comprehension:

>>> import re
>>> i = ['मैसेज','खेलना','दारा','hello','मुद्रण']
>>> [w for w in i if not re.match(r'[A-Z]+', w, re.I)]
['मैसेज', 'खेलना', 'दारा', 'मुद्रण']
like image 28
Burhan Khalid Avatar answered Sep 22 '22 21:09

Burhan Khalid