I have a list and want to separate each list element into more elements, if a comma appears. If a comma appears (Within l2
using this example) I want to duplicate the same element within l1 to
match the numbers of commas found in l2
. This may sound confusing, but below may explain this a bit better
l1 = ['1', '2', '3', '4', '5']
l2 = ['Sam', 'John', 'Steve, Harry, Lucy', 'Mike, Sam', 'Becky']
Intended output:
l1 = ['1', '2', '3', '3', '3', '4', '4', '5']
l2 = ['Sam', 'John', 'Steve', 'Harry', 'Lucy', 'Mike', 'Sam', 'Becky']
I tried x.split(',')
within list, but this created multiple nested lists (shown below):
l2 = [['Sam'], ['John'], ['Steve', 'Harry', 'Lucy']] ..........