如果需要说的话
if <this list has a string in it that matches this rexeg>:
do_stuff()
我发现了一种强大的构造,可以从列表中提取匹配的字符串:
[m.group(1) for l in my_list for m in [my_regex.search(l)] if m]
...但这很难读并且过于复杂。我不需要列表,我只想知道这样的列表中是否有任何内容。
有没有更简单易懂的方法来得到答案?