So basically I take an n value with n = int(input("number of boats")) from user, then taking n amount of integer inputs from a single line (let's say my input is 2 6 3 6 4 7 4 and they wrote 2, I'd only take the first two numbers 2 6) and appending that into a list (which I define before as mylist = []). I want to have them as integers and not a string in my list. How can I do this?
EDIT:
Okay perhaps my wording wasn't the best, so I'll try explaining differently. I'm taking an input from a .txt file and the file has:
3
23 56
36 48
46 97
The 3 at the start determines how many boats there are, and the 23 56 for example are values for the first boat. I want to take input that determines how many boats, then take all the values as input and put them all into one list [23, 56, 36, 48, 46, 97]. Note that I have to use input and not file reading because there will be different values tested. I need the values as integers so I can't take every line as a string.
n. What's the problem with the rest of the numbers?ndetermines how many of the integers I take from the input2 6 3 6 4 7 4re.split(r'\s+', s)(wheresis input string) andr'\s+'is regular expression) will allow you to split the input string based on whitespaces (tabs, spaces etc.). only simplespilt()is not good as user may enter any number of spaces/tabs while inputting integers on console. Please have a look at my answer.