I have a list
myList = ["what is your name", "Hi, how are you", "What about you", "How about a coffee", "How are you"] Now I want to search index of all occurrence of "How" and "what". How can I do this in Pythonic way?
Sounds like a one-liner Python is able to do!
[i for i, j in enumerate(myList) if 'how' in j.lower() or 'what' in j.lower()] This will work, but assumes you do not care about case sensitivity:
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] [j for i, j...] ;)j is the entry of the list, i is the number from enumerate
Howorwhatappears more than once in a string? And what about case sensitivity?