如果任何列表项以字符串开头?

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)

  • 唉打败了我!但是,这是我认为最好的方式. (2认同)