Python oneliner to calculate sum of a column

Sometimes you need to calculate something from the output of another program.

This oneliner calculates number of lines, sum, and average of the second column in the input stream. By default str.split() uses space as a delimiter.

Of course there are several ways to do that. In many languages. This one is in Python.

python -c "import sys;
d=[float(line.split()[1]) for line in sys.stdin.readlines()];
print len(d), sum(d), sum(d)/len(d)"

Remember to put all in one line. Here it is split for easier readability.