且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python在列表列表中查找值

更新时间:2022-11-14 12:09:01

是的,对于初学者来说,不需要范围

Yes, no need for range, for starters

for hay in haystack:
  if needle in hay:
    return hay

如果您确实需要索引,请使用enumerate

And if you really really need the index, use enumerate

for x, hay in enumerate(haystack):
  if needle in hay:
    return x