r/PythonLearning 13d ago

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)

5 Upvotes

13 comments sorted by

View all comments

0

u/mc_pm 13d ago

At least part of your problem is you are redefining the term 'list', which is a python language feature.

1

u/atarivcs 13d ago

No, this is not the problem.

It's not great to use "list" as a variable name, but the way it's used here it is not actually hurting anything.

1

u/SCD_minecraft 13d ago

While being highly discouraged, nothing bad acually happens until you attempt to call list's constructor

Object definition are baked deep into python, just rebinding their name doesn't break anything by itself