check string in a list for substrings and return index

Solutions on MaxInterview for check string in a list for substrings and return index by the best coders in the world

showing results for - "check string in a list for substrings and return index"
Valery
21 Nov 2019
1def get_index(list_of_strings, substring):
2    try:
3        return next(i for i, e in enumerate(list_of_strings) if substring in e)
4    except StopIteration:
5        return len(list_of_strings) - 1
similar questions