Translation in python of C++ idiom
Francois Petitjean
francois.petitjean at noos.fr
Fri Aug 9 11:57:22 EDT 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?
Regards.
(1)
http://www.two-sdg.demon.co.uk/curbralan/papers/minimalism/OmitNeedlessCode.
html
More information about the Python-list
mailing list