HELP Newbie solve this Problem

David Fisher python at rose164.wuh.wustl.edu
Sun Mar 26 02:01:32 EST 2000


----- Original Message -----
From: "Mark Hathaway" <hathawa2 at marshall.edu>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Saturday, March 25, 2000 10:02 PM
Subject: Re: HELP Newbie solve this Problem

[snip]
> Fortran 27 lines unreadable
>
> Python  53 lines commented
>         22 lines uncommented

Well if it's about lines, here's a Python solution in one line (277 chars).
Of course it's slightly harder to read.

import string,operator;ldict={};map(lambda
letter:operator.setitem(ldict,letter,0),map(chr,range(256)));map(lambda
letter:operator.setitem(ldict,letter,ldict[letter]+1),open('data?').read());
print string.join(map(lambda letter:letter+'
'+`ldict[letter]`,string.lowercase),'\n')

This won't work from the Python command line, it has to be run from a
script.  And of course a filename can't have a '?' on a windows box, so it
won't work there either.

This is my first use of lambda (outside of scheme), my mom would be so
proud. :)

dnf









More information about the Python-list mailing list