How to take any number of inputs in python without defining any limit?
This is how to read many integer inputs from user:
inputs = []
while True:
inp = raw_input()
if inp == "":
break
inputs.append(int(inp))
If you want to pass unknow number of arguments to function, you can use *args:
def function(*args):
print args
function(1, 2, 3)
This would print (1, 2, 3)
.
Or you can just use list for that purpose:
def function(numbers):
...
function([1, 2, 3])
from sys import stdin
lines = stdin.read().splitlines()
print(lines)
INPUT
0
1
5
12
22
1424
..
...
OUTPUT
['0', '1', '5', '12', '22', '1424' .. ...]