如何在Python字符串列表中查找出指定字符所在字符串

2025-05-09 13:32:28
推荐回答(1个)
回答1:

re.findall('\\w*{}\\w*'.format(c),','.join(l))
Python 3.5.2 (default, Dec 7 2016, 23:38:49)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import re

>>> l=['sfdsd','ddff']

>>> c='s'

>>> re.findall('\\w*{}\\w*'.format(c),','.join(l))
['sfdsd']