Reputation: 1133
I have a python list
list2 = ['three', 'four', 'five']
and I want to merge it with a new one declared
list1 = ['one', 'two', list2, 'six']
and take the result of
['one', 'two', 'three', 'four', 'five', 'six']
instead of
['one', 'two', ['three', 'four', 'five'], 'six']
could this be possible within the declaration line?
Upvotes: 0
Views: 96
Reputation: 82765
You can unpack the list.
Ex:
list2 = ['three', 'four', 'five']
list1 = ['one', 'two', *list2, 'six']
print(list1)
Output:
['one', 'two', 'three', 'four', 'five', 'six']
Upvotes: 1