7

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:

मैसेज    
खेलना    
दारा    
मुद्रण
Ishpreet
  • 5,230
  • 2
  • 19
  • 35

4 Answers4

9

You can use isalpha() function

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

will give you the result:

मैसेज
खेलना
दारा
मुद्रण
DiligentKarma
  • 5,198
  • 1
  • 30
  • 33
aroy
  • 452
  • 2
  • 10
2

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)]
['मैसेज', 'खेलना', 'दारा', 'मुद्रण']
Frodon
  • 3,684
  • 1
  • 16
  • 33
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
1

You can use filter with regex match:

import re
list(filter(lambda w: not re.match(r'[a-zA-Z]+', w), ['मैसेज','खेलना','दारा','hello','मुद्रण']))
Kirill
  • 7,580
  • 6
  • 44
  • 95
0

You can use Python's regular expression module.

import re
l=['मैसेज','खेलना','दारा','hello','मुद्रण']
for string in l:
    if not re.search(r'[a-zA-Z]', string):
        print(string)
Autonomy
  • 21
  • 2