1

So I have a file that looks like this

2
3
1  2  3  4  5  6

So I need to read this file in three separate variables. For the first two I use something like this:

guests = int(input_file.readline())
length = int(input_file.readline())

But for the third line I need a list, how do I transform that to an integer, I've tried this:

sticks = input_file.readline()
sticks = [int(i) for i in sticks]

But it gives me an error: invalid literal for int() with base 10

wjandrea
  • 28,235
  • 9
  • 60
  • 81

1 Answers1

1

You need to use split() to read multiple integers on a line

sticks = [int(i) for i in sticks.split()]