I would like to get the length of certain values in a list
like:
lst=['ID_CYTY', 'CITY', 'ID_STATE', 'STATE', 'ID_COUNTRY', 'COUNTRY', 'AGE', 'SEX', 'NAME', 'P', 'A1', 'PR', 'V', 'Z', 'M1', 'D1', 'R1', 'CPD', 'CA', 'IN', 'ND', 'I', 'C', 'W', 'NZ', 'EG', 'LOS', 'TO', 'LS', 'EST', 'TR', 'OBS', 'RUT']
I just have another list like:
lst2=['P', 'A1', 'PR', 'V', 'Z', 'M1', 'D1', 'R1', 'CPD', 'CA', 'IN', 'ND', 'I', 'C', 'W']
I would like to get the length of the values before and after lst2
that are inside lst
but the issue here is that lst
could change in length from ID_CITY
to NAME
and NZ
to RUT
, I mean it could have more or less strings after P
to W
. Also, do not have to use the names
of the strings because they could be different from the 0 index to the last index, example:
lst=['CITY', 'ID_STATE', 'STATE', 'ID_COUNTRY', 'COUNTRY', 'AGE', 'SEX', 'A1', 'P', 'PR', 'V', 'Z', 'M1', 'D1', 'R1', 'CPD', 'CA', 'W', 'ND', 'I', 'C', 'IN', 'NZ', 'LOS', 'TO', 'LS', 'EST', 'TR', 'OBS']
I believe it could be done getting the length
of the lst2
and then doing some list indexing to get lengths
inside lst
.
The lst2
it could have theirs strings mixed but it doesn't matter because it must have the same extension from P
to W
no matter if starts or ends with those strings.
Note: I would like to get the values before and after lst2
in lst
in individual list.
What I mean with before and after lst2
inside lst
is:
In the first case it would be:
The length
before P
to W
:
9
the length
from NZ
to RUT
:
9
But this could be different just how I mentioned before.