4 ms·
> x = sys.stdin.readline() > while x: > … > x = sys.stdin.readline() Seeing stuff like that makes me sad. This could be more simply be wri
by teddyh 13y ago
> x = sys.stdin.readline()
> while x:
> …
> x = sys.stdin.readline()
Seeing stuff like that makes me sad. This could be more simply be written as:
for x in sys.stdin:
…
- badman_ting 13y agoThat doesn't strike me as a very worthwhile criticism of code.
- cratermoon 13y agoAs written, the code will write the response string out immediately. The for x in version will block until end-of-input.
- tekacs 13y agoEr... no. No it absolutely wouldn't block until end-of-input. If list comprehensions were being used to precompute the output and the whole list printed from (what you seem to be thinking of) then perhaps yes, but any of: for x in sys.stdin: ... or [... for x in sys.stdin] (where ... is print(func(x)) as per the post) as per the GP post will print response strings as the input comes in.
- teddyh 13y agoThe two versions are functionally identical, which is why the shorter version without repeated code is better.