在python中查找字符串中包含字母和数字值的单词

时间:2018-01-09 10:11:45

标签: python python-3.x

如何在字符串中找到由不同长度的字母和数字值组成的单词

   d = ["his car number is ka99ap9999", "bike that met with accident is kl8ar888"]

我想从d。中获取由字母和数字值组成的单词。

并输出如下

   ka99ap9999, kl8ar888

如果答案已经提供,请提供链接,谢谢

2 个答案:

答案 0 :(得分:3)

如Willem Van Onsem所述,'汽车'也是字母数字。

要将d = ["his car number is ka99ap9999", "bike that met with accident is kl8ar888"] for i in d: for x in i.split(' '): if x.isalnum() and not x.isalpha() and not x.isdigit(): print x 作为输出,首先检查每个单词是否为字母数字,然后检查它不是字母和数字。

python C:/Users/punddin/PycharmProjects/demo/demo.py
ka99ap9999
kl8ar888

代码:

<KrediBilgi>
    <Durum>text1</Durum>
    <GuncelRisk>text2</GuncelRisk>
    ...
</KrediBilgi>

答案 1 :(得分:2)

您似乎在寻找isdigit字符and any isalpha字符>>> d = ["his car number is ka99ap9999", "bike that met with accident is kl8ar888"] >>> [w for s in d for w in s.split() if any(c.isalpha() for c in w) and any(c.isdigit() for c in w)] ['ka99ap9999', 'kl8ar888'] 的字词。只需将其放入列表理解中即可完成:

QChart