python - Extracting specific string after specific character -
new = ['mary 2jay 3ken +', 'mary 2jay 3ken +', 'steven +john '] print(new): mary 2jay 3ken + mary 2jay 3ken + steven +john -
how sign/number after each person's name? i'm wondering whether dict
work in case expected output is:
mary:2 jay:3 ken:+ steven:+ john:-
to index of "+" in string, can use:
index = a_string.index("+")
to check if "+" exist in string, use:
if "+" in a_string: # ...
to iterate list of string, can do:
for text in new: # ...
there fifty ways want. suggest read python tutorial.
edit
you can use regex extract fields name/number
for text in next: couples = re.findall(r"(\s+)\s+(\d+|\+|\-|$)", text) name, num in couples: print(name, num)
Comments
Post a Comment