I have a list like that:
lst = ['something', 'foo1', 'bar1', 'blabla', 'foo2']
Is it possible to get the index of the first item starting with “foo” (foo1) using regular expressions and lst.index() like:
ind = lst.index("some_regex_for_the_item_starting_with_foo") ?
I know I can create a counter and a for loop and use method startswith().
I am curious if I miss some shorter and more elegant way.
I think that it’s ok and you can use startswith method if it do what you really want(i am not sure that you really need regEx here – however code below can be easily modified to use regEx):
Or with regex: