Translation in python of C++ idiom

Andreas Kostyrka andreas at kostyrka.priv.at
Sun Aug 11 15:49:18 EDT 2002


Am Fre, 2002-08-09 um 18.17 schrieb Sean 'Shaleh' Perry:
> actually, most Python coders I see here would probably frown on this style of
> coding.
Yes and no. When it's readable, it's ok.
> 
> import sys, string
> 
> len(sys.stdin.readlines()) # print number of lines on stdin
> 
> print len(string.join(sys.stdin.readlines(), '')) # print number of chars on
> stdin
What about: len(sys.stdin.read())?

> 
> print len(string.split(string.join(sys.stdin.readlines(), ''))) # print number
Again:
len(sys.stdin.read().split())? 
Shorter and better readable. :)

Andreas





More information about the Python-list mailing list