You should know there are two nested list, so there should be two nested for
loop to iterate the list. And you should use another for
loop to iterate the split()
result. The code may be like this:
lines = [['Name0, Location0', 'Phone number0'],
['Name1, Location1', 'Phone number1']]
result = []
for line in lines:
result.append([])
for fields in line:
for token in fields.split(', '):
result[-1].append(token)
print(result)
The output:
[['Name0', 'Location0', 'Phone number0'], ['Name1', 'Location1', 'Phone number1']]
2
solved How to split string in list [closed]