Is it possible to use list comprehension to combine 2 elements in a nested list based on the occurrence of a character, eg: if you encounter '+' combine with the next element? I have some code that does this using nested loops, but trying to achieve using list comprehension.
Input:
l = [['A-2', 'A-3', 'A-4', '+', '100', 'A-5'],['B-2', 'B-3', 'B-4', '+', '500', 'B-5']]
Output:
l = [['A-2', 'A-3', 'A-4', '+100', 'A-5'],['B-2', 'B-3', 'B-4', '+500', 'B-5']]
Code:
for nested in l:
z = iter(nested)
for i in z:
if i == '+':
i = i+next(z)