How to expand a string within a string in python? -
i have string looks this:
1 | xxx | xxx | xxx | yyy*a*b*c | xxx i want expand yyy*a*b*c part string looks this:
1 | xxx | xxx | xxx | yyya | yyyb | yyyc | xxx i have big file delimiter between these strings. have parsed file dictionary looks this:
{'1': ['xxx' , 'xxx', 'xxx', 'yyy*a*b*c', 'xxx' ], '2': ['xxx*d*e*f', ..., 'zzz'], etc} and need have yyy*a*b*c , xxx*d*e*f part replaced additional items in list.
how can in python 3? should expand in string before parse dictionary or after parse dictionary (and how)?
you can using split , simple list comprehension:
def expand_input(input): temp = input.split("*") return [temp[0]+x x in temp[1:]] print(expand_input("yyy*a*b*c")) >>> ['yyya', 'yyyb', 'yyyc']
Comments
Post a Comment