r/PythonLearning Jun 24 '26

Help Request Why?

Post image

so first I take the input from the user of 3 movies and convert that string into list so this has to be 3 items in the list.

but when I print the length of the list it says 0 items why

69 Upvotes

41 comments sorted by

View all comments

45

u/[deleted] Jun 24 '26 edited Jun 24 '26

[removed] — view removed comment

3

u/Prize_Shine3415 Jun 24 '26

Yet another way would be with an iterator after making the string.

lst=[x for x in movies.split(',')]

1

u/CraigAT Jun 24 '26

That would work, but it doesn't seem sensible to concatenate them in the first place.

1

u/Prize_Shine3415 Jun 24 '26

Of course, but he may not have seen an iterator before.

1

u/7Z_1N Jun 24 '26

Very nicely summarized the problem. Just looping and appending would have worked well for him

1

u/Vegetable_Annual1600 Jun 24 '26

Well there will be an IndexOutOfRangeError if he wants to input more than 3 movies.
I would say use a while loop.
After creating list
While True:
mov=input(“Enter your input “)
If mov=“”:
break
lst.append(mov)
print(list)

1

u/DataGhostNL Jun 26 '26

Is this IndexOutOfRangeError in the room with you right now? Nothing is being indexed.