I like using
re
for this, since it can find the element and give you the index directly.>>> mylist = ["---abcdefgh----abc--","--abcd-a--","----------abcdefghij----ab-","-abcdef---a-","----abcdefghijklm----abc--"] >>> [re.search(r"[^-]", x).start() for x in mylist] [3, 2, 10, 1, 4] >>> [re.search(r"[^-]-*$", x).start() for x in mylist] [17, 7, 25, 10, 23]