+ 2

splitlines only returns first list item?

Im trying to use x.splitlines() to separate a three line input into three separate pieces of data to work with individually. However for some reason im only getting the first line, instead of a list of each line. Why is this? x=input() in_list=x.splitlines() print(in_list)

2nd Aug 2020, 7:11 PM
Randy Ziegler
Randy Ziegler - avatar
8 odpowiedzi
+ 8
Randy Ziegler , how are you doing a "3 line input" with one input() call? May be you can give an example? Thanks!
2nd Aug 2020, 7:35 PM
Lothar
Lothar - avatar
+ 7
Randy Ziegler here is an example of splitline() and split() https://code.sololearn.com/cT7CrAQbk7gy/?ref=app
2nd Aug 2020, 7:35 PM
BroFar
BroFar - avatar
+ 6
Randy Ziegler , the task description means that you have to do 3 inputs. Sample used is: 'Eric' 2 'Adam Caroline Rebecca Frank' - the first input can be taken as it is - the second input has to be converted to an int (as input returns everything as string) - the third input is a space separated string. this has to be splitted at the spaces For the last task you can just use split(' '), this results in a list with 4 elements
2nd Aug 2020, 8:15 PM
Lothar
Lothar - avatar
+ 4
ahhhh, you must be doing this here in SoloLearn. Multiline input counts as multiple inputs being gathered here. Your code accepts one input, so the rest are forgotten
2nd Aug 2020, 7:25 PM
Slick
Slick - avatar
+ 2
in_list = x.split('\n') #?
2nd Aug 2020, 7:12 PM
Slick
Slick - avatar
+ 2
Does the same thing, I dont understand why
2nd Aug 2020, 7:23 PM
Randy Ziegler
Randy Ziegler - avatar
+ 2
Lothar its the 'new driver's license' code coach, it says the input is a string, an integer, and another string and I took it to mean a single input of all three that you are responsible for separating
2nd Aug 2020, 8:00 PM
Randy Ziegler
Randy Ziegler - avatar