Characters contain themselves?
WENDUM Denis 47.76.11 (agent)
denis.wendum at pasdepourriels.edf.fr
Fri Apr 7 09:50:53 EDT 2006
While testing recursive algoritms dealing with generic lists I stumbled
on infinite loops which were triggered by the fact that (at least for my
version of Pyton) characters contain themselves.See session:
system prompt% python
Python 2.3.5 (#2, Feb 9 2005, 00:38:15)
[GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
....
>>> 'a' is 'a'
True
>>> 'a' in 'a'
True
>>> 'a' in ['a']
True
>>> ....
Leading to paradoxes and loops objects which contain themselves (and
other kinds of monsters) are killed in set theory with the Axiom of
Foundation:=)
But let's go back to more earthly matters. I couldn't find any clue in a
python FAQ after having googled with the following "Python strings FAQ"
about why this design choice and how to avoid falling in this trap
without having to litter my code everywhere with tests for stringiness
each time I process a generic list of items.
Any hints would be appreciated.
More information about the Python-list
mailing list