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:
मैसेज
खेलना
दारा
मुद्रण
You can use isalpha()
function
l = ['मैसेज', 'खेलना', 'दारा', 'hello', 'मुद्रण']
for word in l:
if not word.isalpha():
print word
will give you the result:
मैसेज
खेलना
दारा
मुद्रण
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)]
['मैसेज', 'खेलना', 'दारा', 'मुद्रण']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With