strange for loop construct

Sardaukary at Sardaukary at
Fri Jan 5 21:39:08 CET 2007

I was googling for an example of the classic word frequency program in
Python as I'm just learning the language, and wanted to see how other
people implemented it.

I found this blog post
(with a much more concise version than I managed) but I can't seem to
find any mention in various Python documentation of the following

wordfreq = [wordlist.count(p) for p in wordlist]

I would expect

for p in wordlist:

I didn't know you could have an expression in the same line.

More information about the Python-list mailing list