In article <[EMAIL PROTECTED]>, Alex Martelli <[EMAIL PROTECTED]> wrote: >Cameron Laird <[EMAIL PROTECTED]> wrote: > >> In article <[EMAIL PROTECTED]>, >> Alex Martelli <[EMAIL PROTECTED]> wrote: >> . >> . >> . >> >My preference would be (with the original definition for >> >words_of_the_file) to code >> > >> > numwords = sum(1 for w in words_of_the_file(thefilepath)) >> . >> . >> . >> There are times when >> >> numwords = len(list(words_of_the_file(thefilepath)) >> >> will be advantageous. > >Can you please give some examples? None comes readily to mind... . . . Maybe in an alternative universe where Python style emphasizes functional expressions. This thread--or at least the follow-ups to my rather frivolous observation--illustrate how distinct is Python's direction.
If we could neglect memory impact, and procedural side-effects, then, sure, I'd argue for my len(list(...)) formulation, on the expressive grounds that it doesn't require the two "magic tokens" '1' and 'w'. Does category theory have a term for formulas of the sort that introduce a free variable only to ignore (discard, ...) it? There certainly are times when that's apt ... -- http://mail.python.org/mailman/listinfo/python-list