Tuple comprehension

Magnus Lie Hetland mlh at vier.idi.ntnu.no
Wed Apr 10 23:18:58 EDT 2002


It seems this has been brought up before, but I could only find two
posts about it (about a year old). The question is: Could we have
tuple comprehensions?

The argument I saw used earlier was based on the author's
preconceptions about tuples being primarily "records" and not
"containers". The only defining quality I see to tuples as opposed to
lists is that they are immutable. (Yes, I see the "recordness", but I
don't think it's an argument against tuple comprehension.)

Tuple comprehension could be useful when creating a tuple based on
another sequence, where you'd iterate over the values, doing something
to each of them. Of course you can do tuple([x for x in ...]). If
adding tuple comprehensions is too costly, then this is perfectly
viable. (I guess a tuple comprehension would have to create a list or
something similar internally anyway...)

As far as I can see, the PEP on dict comprehension is still open... I
think both dictionary comprehension and tuple comprehension seem like
natural parallels to list comprehension. But then I would, wouldn't I?
<wink>

--
Magnus Lie Hetland                                  The Anygui Project
http://hetland.org                                  http://anygui.org



More information about the Python-list mailing list