假设我的列表有 ["Apple","ball","caT","dog"] 然后它应该给我结果 'ball 和 'dog'。
如何使用 re.findall() 做到这一点?
请您参考如下方法:
这里根本不需要re.findall()。
使用:
[s for s in inputlist if s.islower()]
str.islower() method如果字符串中的所有字母都是小写,则返回 True。
演示:
>>> inputlist = ["Apple","ball","caT","dog"]
>>> [s for s in inputlist if s.islower()]
['ball', 'dog']
使用re.findall() 在较大 字符串中查找小写文本,而不是在列表中:
>>> import re
>>> re.findall(r'\b[a-z]+\b', 'The quick Brown Fox jumped!')
['quick', 'jumped']
