So I have a list of strings such as this:
my_list=["---abcdefgh----abc--","--abcd-a--","----------abcdefghij----ab-","-abcdef---a-","----abcdefghijklm----abc--"]
I want, for each string, to retrieve the position where the first and last letters appear. Or in other words, to find the position of the first character that isn't a "-" and the position of the last character that isn't a "-". It would be perfect if I could save the result as two lists, one of the first positions and another for the last.
I've tried using find() at least for the first position but since the character I'm trying to find is one of several letters, I don't know how to do it.
The output I wanted was something like this:
first_positions=[3,2,10,1,4]
last_positions=[17,7,25,11,23]
Thanks in advance for any answer
my_list=["---abcdefgh----abc--","--abcd-a--","----------abcdefghij----ab-","-abcdef---a-","----abcdefghijklm----abc--"]
I want, for each string, to retrieve the position where the first and last letters appear. Or in other words, to find the position of the first character that isn't a "-" and the position of the last character that isn't a "-". It would be perfect if I could save the result as two lists, one of the first positions and another for the last.
I've tried using find() at least for the first position but since the character I'm trying to find is one of several letters, I don't know how to do it.
The output I wanted was something like this:
first_positions=[3,2,10,1,4]
last_positions=[17,7,25,11,23]
Thanks in advance for any answer