rea*_*aco 10 python list-comprehension
我是Python的新手(2周!)并且正在努力解决以下问题:
我有一个URL列表,我想迭代并找到某些URL.为此,我想测试URL中存在元组的任何成员.
我已经发现我需要一个any()语句,但无法正确获取语法:
allurls = [<big list of URLs>]
words = ('bob', 'fred', 'tom')
urlsIwant = [x for x in allurls if any(w for w in words) in x]
Run Code Online (Sandbox Code Playgroud)
抓住我
TypeError: 'in <string>' requires string as left operand, not bool
Run Code Online (Sandbox Code Playgroud)
我不认为它是相关的,但我的实际代码是
urlsIwant = sorted(set([x for x in allurls if dict['value'] in x and any(w for w in words) in x]))
Run Code Online (Sandbox Code Playgroud)
ssh*_*124 12
包括in x在any():
urlsIwant = [x for x in allurls if any(w in x for w in words)]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5137 次 |
| 最近记录: |