What's the equivalent for while (cin >> var) in python?
There's no direct equivalent in Python. But you can simulate it with two nested loops:
for line in sys.stdin:
for var in line.split():
If you need something other than a string you'll need to convert it in a separate step:
var = int(var)
This could be helpfull.
import sys
for line in sys.stdin:
#Do stuff