strange for loop construct
Gabriel Genellina
gagsl-py at yahoo.com.ar
Fri Jan 5 15:49:48 EST 2007
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
More information about the Python-list
mailing list