chatzich
chatzich

Reputation: 1133

Extend a python list elements on the list's declaration instead of append

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

Answers (1)

Rakesh
Rakesh

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

Related Questions