'For' loop symmetry with list comprehensions.

Hannu Kankaanpää hanzspam at yahoo.com.au
Fri Jul 4 17:03:27 CEST 2003


"Sean Ross" <sross at connectmail.carleton.ca> wrote in message news:<LUYMa.5841$eF3.721551 at news20.bellglobal.com>...
> (being symmetrical) we should also be able to write:
> 
> >>> msgs = []
> >>> for x in words:
> ...  for y in otherwords:
> ...   msgs.append("%s %s"%(x,y))
> ...
> >>> msgs
> ['hello foo', 'hello bar', 'bonjour foo', 'bonjour bar']
> 
> 
> as follows:
> 
> msgs = []
> for x in words for y in otherwords:
>     msgs.append("%s %s"%(x,y))
> 
> 
> If you really want symmetry, well, this is symmetrical. Do you want this as
> well?
> 
> -0
> Sean

Ok, I see. Just because new for syntax had to be added to work on one
line in list comprehensions doesn't mean that rest of the language
should be polluted with the one-liner syntax too. So it wasn't that
good of an idea after all :P




More information about the Python-list mailing list