Re:Homogenization of scientific computing – Python is eating...
by ajayjain on Saturday January 11, 2014 @03:21AM
(#7042031)
I'm not too familiar with Python, but this is case sensitive unlike benhoyt's examples. Would this be case insensitive?
lines = [line for line in open("bible.txt")]
words = [word.lower() for line in lines for word in line.split()]
counts = {word:0 for word in words}
for word in words:
counts[word] += 1
Re:Homogenization of scientific computing – Python is eating...
by gejjaxxita on Tuesday January 14, 2014 @10:19PM
(#7061452)
yes!
Re:Homogenization of scientific computing – Python is eating...
by burntsushi on Thursday January 09, 2014 @06:25PM
(#7033984)
> A bit inefficient in the dictionary comprehension, but easy to read.
If you allow one import to sneak in, I think a `defaultdict` would do nicely. :-)
The "lines=" and "words=" can be compressed into one line, but I figure this is a bit easier to read for people who aren't familiar with nested list comprehensions.