Translation in python of C++ idiom

Francois Petitjean francois.petitjean at
Fri Aug 9 17:57:22 CEST 2002

In a paper entitled "Minimalism: Omit Needless Code" (1), Kevlin Henney
advocates a concise coding style and for instance the following snippet :
typedef std::istream_iterator<std::string> in;
std::cout << std::distance(in(std::cin), in());
is given to print the number of words in a textfile or stream. And by
replacing the typedef by
typedef std::istreambuf_iterator<char> in;
we count chars.

To print the number of lines :
typedef std::istreambuf_iterator<char> in;
std::cout << std::count(in(std::cin), in(), '\n');

So, what would be the equivalent in Python?



More information about the Python-list mailing list