[Tutor] implied tuple in a list comprehension
Alan Gauld
alan.gauld at btinternet.com
Fri Aug 2 21:07:25 CEST 2013
On 02/08/13 19:13, Jim Mooney wrote:
> comma, then word in S, which made no sense, instead of unpacking -
> word for (idx, word) in S. Done in again by the implied tuple ;')
Just to pick up a point that might be confusing you.
A tuple does not need parentheses.
>>> tup = 5,4
>>> tup
(5, 4)
>>> type(tup)
<type 'tuple'>
tup is a tuple. Its not implied it is complete. The parentheses
are only added to avoid ambiguity and aid readability.
For example a single item tuple is more obvious with
the parens:
t = (6,) # t=6, works but is much harder to see.
HTH,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list