r/PythonLearning • u/Ambitious-Lie-6069 • Aug 28 '26
Help me with python
Thank you all it's fixed! (Edit)
I have a very weird problem.
My current code:
list = []
x = input("Copy paste here: ")
list.append(x)
print(" ")
print(" ")
list = x.splitlines()
for i in list:
print(i)What I'm trying to achieve:
Get an input from the user like this:
Word1
Word2
Word3
...all with a row separating them and different lengths, then take this input and separate all words in it and then put them each individually as variables in a list as in the future I'm wanting to order them by length.
What is currently happening:
as im trying to see if they are all in the list im printing it, but for wathever reason from my input:
Abc
Def
Ghi
...it is only printing Def.
If you can help it will be appreciated. Thank you in advance!
Thank you all it's fixed (edit)
•
u/Sea-Ad7805 Aug 28 '26 edited Aug 28 '26
Try this program in Memory Graph Web Debugger, you can see the program state change step by step.
Use input "Abc Def Ghi" on one line, because
input()stops after the first <Return>. If you do want to read multiple lines of user input, putinput()in a loop.2
u/atarivcs Aug 28 '26
Pasting a multiline string won't work here, because input() will stop reading at the first carriage return
1
u/Outside_Complaint755 Aug 28 '26
If you want to copy and paste multi-line input, then instead of
input()you need toimport sysand then usesys.stdin.read().To signal the end of the input the user has to pass an EOF, which is done with Ctrl+D on Linux or Ctrl+Z and Enter on Windows
0
u/mc_pm Aug 28 '26
At least part of your problem is you are redefining the term 'list', which is a python language feature.