"Fredrik Lundh" <[EMAIL PROTECTED]> writes: > Mike Meyer wrote: >> So why the $*@& (please excuse my Perl) does "for x in 1, 2, 3" work? > because the syntax says so: > http://docs.python.org/ref/for.html
In other words, "Because that's the way we do things." >> Seriously. Why doesn't this have to be phrased as "for x in list((1, >> 2, 3))", just like you have to write list((1, 2, 3)).count(1), etc.? > because anything that supports [] can be iterated over. That's false. Anything that has __getitem__ supports []. To be iterated over, it has to have __iter__, or an __getitem__ that works on integers properly. Writing a class that meets the first without meeting the second is easy. Dicts used to qualify, and tuples could be iterated over at that time. Not really very satisfactory reasons. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list