markroxor
markroxor

Reputation: 6476

Iterate through each integer python separated by a blankspace/endline

I am a Python 2.7 user who recently switched to python3. While reading integers separated by a blackspace/endline I used nex = iter(map(int,stdin.read().split())).next, where nex() acts as a function to input integers (Suppose for inputting an integral value in x -> x=nex(). But in python3 this doesn't seem to work. Someone please propose a workaround for using the same in Python3.

Upvotes: 0

Views: 36

Answers (1)

jfs
jfs

Reputation: 414179

.next() method is called .__next__() in Python 3. You could use next() function to write single-source Python 2/3 compatible code:

from functools import partial

nex = partial(next, iter(iterable))
print(nex())

Upvotes: 1

Related Questions