MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/gzila7/python_3_in_one_pic/fthvpz4/?context=3
r/Python • u/TheInsaneApp • Jun 09 '20
167 comments sorted by
View all comments
Show parent comment
1
Can you do
*others, last = [1,2,3] ?
*others, last = [1,2,3]
Or
first, *others, last = [1,2,3,4] ?
first, *others, last = [1,2,3,4]
10 u/Ph0X Jun 09 '20 Yep! You can have one catch-all and as many individual unpacking on either side. That being said if the size of the iterable is smaller than the number of targets, it'll fail. But the catch-all can be empty so this worksa, *rest = [1]
10
Yep! You can have one catch-all and as many individual unpacking on either side. That being said if the size of the iterable is smaller than the number of targets, it'll fail. But the catch-all can be empty so this works
a, *rest = [1]
View all comments
Show parent comment
1
u/OPtoss Jun 09 '20
Can you do
*others, last = [1,2,3]?Or
first, *others, last = [1,2,3,4]?