I was wondering how would you find the index of a element in a list if you only had part of it. For example
list = ["this", "is", "an", "example", "for", "python"]
Straightforward for loop:
def find_starts(val, my_list): for i, v in my_list: if v.startswith(val): return i
(If there is no match then this returns
None.) This could be made neater with a list comprehension: see this related question for more details.