tkb*_*kbx 10 python list startswith
我正在尝试检查列表中的任何项目是否以某个字符串开头.我怎么能用for循环呢?IE:
anyStartsWith = False
for item in myList:
if item.startsWith('qwerty'):
anyStartsWith = True
Run Code Online (Sandbox Code Playgroud)
Ash*_*ary 39
用途any()
:
any(item.startswith('qwerty') for item in myList)
Run Code Online (Sandbox Code Playgroud)