3 ms·
Single-element tuple unpacking? I've never found a case where I knew there would only be one element in a list, but I do use tuple unpacking all of the time.
by agentultra 16y ago
Single-element tuple unpacking?
I've never found a case where I knew there would only be one element in a list, but I do use tuple unpacking all of the time.
Pretty cool I guess; didn't know it wasn't a common idiom. Good to know. Thanks for sharing. :)
- marcinw 16y agohttp://docs.python.org/library/struct.html#struct.unpack http://docs.python.org/library/struct.html#struct.unpack """The result is a tuple even if it contains exactly one item.""" I run into this constantly using struct.unpack(), and I find the author's idiom to be ideal way to handle this. I will use this from now on.