Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
yay! it worked!
#1
i don't remember reading about this, but i decided to try it and see.  what could i lose?  a few seconds of my time?  just trying it beats asking others if it would work, or in simple cases, like this, trying to find it in one of the many documents, references, or tutorials.  i had no idea where to look, but i knew where to try it.

i have a structure like ['xyzzy','woot',['foo','bar']] which i wanted to split up into 4 variables.  so i could do
    a, b, temp = structure
    c, d = temp
but, i wanted to do it in just one line, so i just up and tried this:
    a, b, (c, d) = structure
and it worked!  and it only spent less than a minute of time to discover this ... not more than if i had read the document where this capability is described.

but i spent a few minutes putting together this post.  oh, and it worked in both python2 (2.7.12) and python3 (3.5.2).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020