News for hackers. Stuff that matters.
Re:Homogenization of scientific computing – Python is eating... by yohanatan on Thursday January 09, 2014 @03:04PM (#7032796)
Actually that's not 'highly proficient'. This is:

    def read_words(words_file):
        return [word for line in open(words_file, 'r') for word in line.split()]
    len(set(read_words('test.txt')))
Re:Homogenization of scientific computing – Python is eating... by bnolsen on Thursday January 09, 2014 @03:26PM (#7032946)
smashing tons of crap together isn't necessarily "highly proficient". In some cases it makes things harder to read and/or harder to maintain and many times certainly harder to edit.
Re:Homogenization of scientific computing – Python is eating... by eeshanC on Friday January 10, 2014 @02:40AM (#7035567)
True that. But there is also another side to this story, where such nested calls translates naturally to what we are thinking, i.e.

length(unique(text)) comes from the thought "How many(length()) unique (unique()) words are there in this text(text)?"

Re:Homogenization of scientific computing – Python is eating... by mbq on Thursday January 09, 2014 @03:09PM (#7032839)
R version for comparison (;

    length(unique(scan('test.txt',character(),sep=" ")))
Re:Homogenization of scientific computing – Python is eating... by eeshanC on Friday January 10, 2014 @02:17AM (#7035496)
Very clean. 1 small change to make it count of frequencies-

table(scan('test.txt',character(),sep=" "))

Re:Homogenization of scientific computing – Python is eating... by agumonkey on Thursday January 09, 2014 @03:28PM (#7032962)
Don't know when set comprehensions and resource handlers were introduced so that might not run everywhere

    def read_words(words_file):
        with open(words_file, 'r') as f:
            return {word for line in f for word in line.split()}
Re:Homogenization of scientific computing – Python is eating... by pwang on Thursday January 09, 2014 @03:54PM (#7033147)
len(set(open("test.txt").read().split()))
Re:Homogenization of scientific computing – Python is eating... by wyager on Thursday January 09, 2014 @05:37PM (#7033784)
Oh, I like this one. Not quite what OP asked, but very clean.
Re:Homogenization of scientific computing – Python is eating... by jessaustin on Thursday January 09, 2014 @04:43PM (#7033470)
GP asked for counts, not uniques.
Re:Homogenization of scientific computing – Python is eating... by yohanatan on Thursday January 09, 2014 @05:17PM (#7033675)
Oops, you're right.

    words = open("test.txt").read().split()
    [(k, len(list(g))) for k, g in groupby(words, lambda x: x)]
Re:Homogenization of scientific computing – Python is eating... by leephillips on Thursday January 09, 2014 @05:58PM (#7033873)
Doesn't that require an "import itertools"?
Re:Homogenization of scientific computing – Python is eating... by yohanatan on Wednesday January 15, 2014 @02:22PM (#7065506)
Yup. Sorry.
Re:Homogenization of scientific computing – Python is eating... by yohanatan on Thursday January 09, 2014 @05:20PM (#7033692)
Oops, should have been this:

    words = open("test.txt").read().split()
    [(k, len(list(g))) for k, g in groupby(words, lambda x: x)]
Re:Homogenization of scientific computing – Python is eating... by hnriot on Thursday January 09, 2014 @08:57PM (#7034599)
except that's wrong, all you're doing is counting the number of unique words, and you didn't even consider Foo and foo as the same in your example. Part of proficiency is understanding the problem.