Can somebody help me convert list like this:
list1 = [('Monday', [1, 2]), ('Tuesday', [3, 4])]
to the list like that:
list2 = [['Monday', 1, 2], ['Tuesday', 3, 4]
Any help will be appretiated.
CodePudding user response:
list1 = [('Monday', [1, 2]), ('Tuesday', [3, 4])]
list2 = [[e[0], *e[1]] for e in list1]
print(list2)
prints
[['Monday', 1, 2], ['Tuesday', 3, 4]]
CodePudding user response:
If the format is fixed, use unpacking:
list1 = [('Monday', [1, 2]), ('Tuesday', [3, 4])]
list2 = [[a, *b] for a, b in list1]
output: [['Monday', 1, 2], ['Tuesday', 3, 4]]