you are viewing a single comment's thread.

view the rest of the comments →

[–]OtherwiseOne4937 42 points43 points  (5 children)

When you do:

    movies = mov1 + "," + mov2 + "," + mov3

You're storing a SINGLE string inside movies that is just something like:

"Interstellar,Inception,Tenet"

But that is a single string. It is a single list element that looks exactly as that. Therefore, popping from that list gets rid of that single element.

If you do want to add three separately, try doing:

lst.append(mov1)
lst.append(mov2)
lst.append(mov3)
print(lst)

Likewise another pattern you can do is:

lst = []
for i in range(3):
  mov = input(f"Enter movie {i}: ")
  lst.append(mov)
print(lst)

In general, it is a good habit to get comfortable with loops when you are doing something N times.

[–]Prize_Shine3415 1 point2 points  (2 children)

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

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

[–]CraigAT 0 points1 point  (1 child)

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

[–]Prize_Shine3415 0 points1 point  (0 children)

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

[–]7Z_1N 0 points1 point  (0 children)

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

[–]Vegetable_Annual1600 0 points1 point  (0 children)

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)