strange for loop construct
Gabriel Genellina
gagsl-py at yahoo.com.ar
Fri Jan 5 15:49:48 EST 2007
More information about the Python-list mailing list
Fri Jan 5 15:49:48 EST 2007
- Previous message (by thread): strange for loop construct
- Next message (by thread): strange for loop construct
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At Friday 5/1/2007 17:39, Sardaukary at gmail.com wrote: >wordfreq = [wordlist.count(p) for p in wordlist] > >I would expect > >for p in wordlist: > wordfreq.append(wordlist.count(p)) > > >I didn't know you could have an expression in the same line. That's known as a "list comprehension" and is roughly equivalent to your code. Section 5 of the tutorial covers them. http://docs.python.org/tut/node7.html -- Gabriel Genellina Softlab SRL __________________________________________________ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas
- Previous message (by thread): strange for loop construct
- Next message (by thread): strange for loop construct
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list