HELP Newbie solve this Problem

n_i_k at my-deja.com n_i_k at my-deja.com
Mon Mar 27 03:21:42 EST 2000


In article <8bkt68$gbl$1 at slb7.atl.mindspring.net>,
"Andrew Dalke" <dalke at acm.org> wrote:
> Ahh, c'mon. You can do better than that. I count 279 characters
> in that solution. Here's one in one line and 167 characters
> (with several bugs introduced since the original post did smell
> like a homework problem):
>
> exec "import string;v=[0]*26
> for c in map(ord,string.lower(open('data').read())):
> if c >= 64 and c <= 89: v[c-64]=v[c-64]+1
> for i in range(1,26):print chr(i+64),v[i]
> "
Well, I can't resist. Here is one in 97 characters:
import re
for c in re.string.lowercase:
print c,re.subn("(?i)"+c,"",open("data").read())[1]
Obiously not optimized for efficiency. ;)
// Niklas


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list