2024-03-29 02:07:26 发布
网友
我有一张单子
myList = ["what is your name", "Hi, how are you", "What about you", "How about a coffee", "How are you"]
现在我要搜索"How"和"what"所有出现的索引。我怎么能用Python的方式来做这件事?在
"How"
"what"
听起来像一条单行线的Python也能做到!在
[i for i, j in enumerate(myList) if 'how' in j.lower() or 'what' in j.lower()]
这是可行的,但假设您不关心大小写敏感度:
myList = ["what is your name","Hi, how are you","What about you","How about a coffee","How are you"] duplicate = "how are you" index_list_of_duplicate = [i for i,j in enumerate(myList) if duplicate in j.lower()] print index_list_of_duplicate [1,4]
听起来像一条单行线的Python也能做到!在
这是可行的,但假设您不关心大小写敏感度:
相关问题 更多 >
编程相关推荐