Python Forum
yay! it worked! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: yay! it worked! (/thread-6948.html)



yay! it worked! - Skaperen - Dec-15-2017

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).