Python仅保留列表中的字母数字单词 [英] Python keep only alphanumeric words from list

查看:1291
本文介绍了Python仅保留列表中的字母数字单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似以下内容的单词列表

I have a list of words resembling the following

    mylist=["hi", "h_ello", "how're", "you", "@list"]

我想提取所有非字母数字字符以给出如下结果:

I would like to pull out all of the non-alpha numeric characters to give a results such as:

                  "h_ello", "how're", "@list"

请注意,我在现实生活中的清单要长得多,它包含一些非字母数字实例,例如〜,?,>,=,+等.

Please note I have a much longer list in real life, and it contains some non-alpha numeric instances such as ~, ?, >, =, + etc.

有人知道怎么做吗? 谢谢

Does anyone know how to do this ,please? Thank you

推荐答案

使用str.isalpha()

例如:

mylist=["hi", "h_ello", "how're", "you", "@list"]
print([i for i in mylist if not i.isalpha()])

输出:

['h_ello', "how're", '@list']

这篇关于Python仅保留列表中的字母数字单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆