How can I read N ints from the input, and stop reading when I find \n? Also, how can I add them to an array that I can work with?
I’m looking for something like this from C but in python
while(scanf("%d%c",&somearray[i],&c)!=EOF){
i++;
if (c == '\n'){
break;
}
}
In Python 2:
raw_input()reads a whole line from the input (stopping at the\n) as a string..split()creates a list of strings by splitting the input into words.map(int, ...)creates integers from those words.In Python 3
raw_inputhas been renamed toinputandmapreturns an iterator rather than a list, so a couple of changes need to be made: