[Python-Dev] list of constants -> tuple of constants

Raymond Hettinger python at rcn.com
Sun Feb 6 19:03:56 CET 2005


[Skip]
> If lists are conceptually like vectors or
> arrays
> in other languages and tuples are like C structs or Pascal records,
then
> by
> converting from list to tuple form you've somehow muddied the data
> structure
> water just to take advantage of tuples' immutability.

In the context of literals used with the "in" operator, practices are
widely divergent within the standard library and within the tutorial.
Even within a single module, there were arbitrary switches between "x in
[1,2,3]" and "x in (1,2,3)" and "x in 1,2,3".

It seems that the list-as-arrays-tuple-as-records guideline is not
meaningful or applicable in the context of the "in" operator.
Proscribing tuple.__contains__ and tuple.__iter__ carrys the notion a
bit too far.





> Wouldn't it be better to have the peephole optimizer recognize the
> throwaway
> nature of lists 

That's a good idea.  Implementing it will be more straight-forward after
the AST branch gets completed.



Raymond



More information about the Python-Dev mailing list