Tuple comprehension

Max M maxm at mxm.dk
Thu Apr 11 03:53:22 EDT 2002


Sean 'Shaleh' Perry wrote:
> On 11-Apr-2002 Emile van Sebille wrote:
> 
>>Magnus Lie Hetland
>>
>>>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>
>>>
>>Why not just tuple([my list comp]) ?
>>
> 
> because it feels wrong to create a (possibly large) list and then duplicate it
> into a tuple.  My mind sees that and thinks 'overhead'.

The natural way to implement it in practice is almost certainly just do 
it behind your back.

Append takes a mutable sequence.

The most effcient mutable sequence in Python is the List, so why should 
they make a "better" mutable sequence to support tuple comprehensions?

And if they did make a better mutable sequence should there really be 
two of them? That would be redundant code that would need to be 
refactored. Probably into the list class.

Then they would use the list class to implement tuple comprehensions...

 From here on my arguments gets a wee bit circular ...

regards Max M




More information about the Python-list mailing list