I have some code in Python:
repost_pid = row[0]
repost_permalink = row[1]
repost_domain = row[2]
repost_title = row[3]
repost_submitter = row[4]
Is there a one-liner way to assign these variables?
Also, what would I do if I wanted to skip a value?
Yes you can separate each variable with a ,
to perform unpacking
repost_pid, repost_permalink, repost_domain, repost_title, repost_submitter = row
If there is a particular value that you are not concerned about, the convention is to assign it to an underscore variable, e.g.
repost_pid, repost_permalink, _, repost_title, repost_submitter = row
If you want to skip a value in sequence unpacking, you can do:
>>> row
[0, 1, 2, 3]
>>> r0,r1,r3=row[0:2]+[row[3]]
>>> r0,r1,r3
(0, 1, 3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With