How to remove english alphabets from list in python
Asked Answered
S

4

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:

मैसेज    
खेलना    
दारा    
मुद्रण
Sweepings answered 19/7, 2016 at 5:1 Comment(0)
E
9

You can use isalpha() function

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

will give you the result:

मैसेज
खेलना
दारा
मुद्रण
Eumenides answered 19/7, 2016 at 5:19 Comment(0)
F
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)]
['मैसेज', 'खेलना', 'दारा', 'मुद्रण']
Fiber answered 19/7, 2016 at 5:29 Comment(0)
C
1

You can use filter with regex match:

import re
list(filter(lambda w: not re.match(r'[a-zA-Z]+', w), ['मैसेज','खेलना','दारा','hello','मुद्रण']))
Cabrilla answered 19/7, 2016 at 5:21 Comment(0)
W
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)
Whirly answered 19/7, 2016 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.