You can solve it differently. My approach was:
- First split the input string by
whitespaces
and you will get a list - Split the 3rd element of the list by
,
and get another list. - within a loop, each time make a new copy of the splitted input and append to another list.
- Modify 3rd element every inner list items of the bigger lists
- Print them as needed
You can look at the below code:
inp="100 name1 a=1,b=2 place1"
splitedWords = inp.split()
result= splitedWords[2].split(",")
lst=[]
for i in range(len(result)):
lst.append(splitedWords[:])
for i in lst:
i[2] = result.pop(0)
print " ".join(i)
Output:
100 name1 a=1 place1
100 name1 b=2 place1