Interesting... It behaves correctly for strings if you use a list inside the comprehension instead of a tuple. ~Sean
On Mon, Dec 29, 2008 at 7:01 AM, Feat <j...@ai.univ-paris8.fr> wrote: > I thought a string was stored as a unique object, so why isn't this > evidenced by the code below ? > > Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > >>> [light is 'green' for light in 'green', 'red'] > [True, False] > >>> color = 'green' > >>> [light is 'green' for light in 'green', 'red'] > [False, False] > >>> color = 1 > >>> [light is 'green' for light in 'green', 'red'] > [True, False] > > whereas: > > >>> [x is 1 for x in 1, 2] > [True, False] > > whether the value 1 is assigned to some other variable or not... the id of > 1 doesn't vary -- just what is the rationale behind that? > > I know I could use the == predicate instead, but just how many different > greens (with different ids) can there be, and how do I know which one is > under focus at a given time? > > -- > Jym Feat ~ Paris FR 75018 > _______________________________________________ > Pythonmac-SIG maillist - Pythonmac-SIG@python.org > http://mail.python.org/mailman/listinfo/pythonmac-sig >
_______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig