如何从python

时间:2016-07-19 05:01:48

标签: python non-english

我有一个包含一些英文文本的列表,而另一个在Hindi中。我想删除用英语写的列表中的所有元素。怎么实现呢?

示例:如何从下面的列表hello中删除L

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

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

预期产出:

मैसेज    
खेलना    
दारा    
मुद्रण

4 个答案:

答案 0 :(得分:7)

您可以使用isalpha()功能

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

会给你结果:

मैसेज
खेलना
दारा
मुद्रण

答案 1 :(得分:2)

简单列表理解如何:

>>> import re
>>> i = ['मैसेज','खेलना','दारा','hello','मुद्रण']
>>> [w for w in i if not re.match(r'[A-Z]+', w, re.I)]
['मैसेज', 'खेलना', 'दारा', 'मुद्रण']

答案 2 :(得分:1)

您可以将filter与正则表达式match一起使用:

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

答案 3 :(得分:0)

您可以使用Python的正则表达式模块。

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