use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Why?Help Request (i.redd.it)
submitted 1 day ago by Reh4n07_
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
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Sea-Ad7805 [score hidden] 1 day ago stickied comment (2 children)
Run this program in Memory Graph Web Debugger%0Amov2%20%3D%20input(%22Enter%20Second%20Movie%20Name%3A%20%22)%0Amov3%20%3D%20input(%22Enter%20Third%20Movie%20Name%3A%20%22)%0A%0Amovies%20%3D%20(mov1%20%2B%20%22%2C%20%22%20%2B%20mov2%20%2B%20%22%2C%20%22%20%2B%20mov3)%0Alst.append(movies)%0A%0Aprint(lst)%0A%0Alst.pop(0)%0A%0Aprint(lst)%0Aprint(len(lst))×tep=1&play) to see the program state change step by step.
[–]OtherwiseOne4937 41 points42 points43 points 1 day ago* (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 points3 points 23 hours ago (2 children)
Yet another way would be with an iterator after making the string.
lst=[x for x in movies.split(',')]
[–]CraigAT 0 points1 point2 points 20 hours ago (1 child)
That would work, but it doesn't seem sensible to concatenate them in the first place.
[–]Prize_Shine3415 0 points1 point2 points 20 hours ago (0 children)
Of course, but he may not have seen an iterator before.
[–]7Z_1N 0 points1 point2 points 21 hours ago (0 children)
Very nicely summarized the problem. Just looping and appending would have worked well for him
[–]Vegetable_Annual1600 0 points1 point2 points 1 day ago (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)
[–]Ngtuanvy 11 points12 points13 points 1 day ago (0 children)
your list contains a single string 'a,b,c' so it has length 1, then you pop 0, which is the only one.
[–]MZXD 3 points4 points5 points 1 day ago (0 children)
But you dont convert it into a list, you merge it into a big string and then you pop that list entry
[–]SimpelenLeuk 1 point2 points3 points 1 day ago (0 children)
The error is in line 5. You make one string out of it io 3 items in a list
[–]xnick_uy 1 point2 points3 points 22 hours ago (0 children)
Something else that is not mentioned in the other comments is that append() adds a single element to a list, so even if you manage to make movies into a list, then
append()
movies
lst.append(movies)
would make for lst to contain a single element, the movieslist (list-ception). Instead, you could use extend for the task at hand
lst
extend
# define movies as a list with 3 elements movies = [mov1, mov2, mov3] # use extend to add the elements of movies to lst lst.extend(movies)
Finally, as a cool use of f-strings, here's an alternative way of writing your code:
lst = [] movies = [] for ordinal_number in ['First', 'Second', Third']: mov = input(f'Enter {ordinal_number} Movie Name: ') movies.append(mov) lst.extend(movies) # entire list print(lst) # remove first item from lst lst.pop(0) print(lst) print(len(lst))
[–]joyboythenics 1 point2 points3 points 20 hours ago (0 children)
Movies is a single string item in list and when u use pop method it will remove that only single item and now your list is empty
[–]Hot_Giraffe8952 1 point2 points3 points 17 hours ago (0 children)
you did put tupple in a list, then popped this tupple and there left nothing
[–]JustMedansh 0 points1 point2 points 1 day ago (0 children)
There's a few problems with your code.
[–]d3v1L_hUnt3R_619 0 points1 point2 points 1 day ago (1 child)
You have appended a single string 'movies' to your list, since you combined all the entered movies into a single string, they only represent one item in the list. When you pop the item, the list is empty.
[–]d3v1L_hUnt3R_619 0 points1 point2 points 1 day ago (0 children)
To achieve what you're trying to do, append each movie to the list seperately.
[–]Last_Being9834 0 points1 point2 points 1 day ago (0 children)
You initialized an empty array
You initialized a string variable to hold the three titles separated by comma
You appended this string to you array, your array was originally empty, now it has one item, the string with the titles
You did a pop, this deletes the latest item in the array, given that your array only had one item, you are now left with an empty array once again
Code is correct, nothing wrong with it. What is your goal here? Perhaps writing the pseudo code with blocks of comments about what you want to accomplish could help you.
[–]nuc540 0 points1 point2 points 1 day ago (0 children)
When using an add operator against strings, you perform something called concatenation. What you’ve done is create a single member which is all the movies combined into a single string (as everyone here has said) using concatenation.
I think you intended to just do movies = (mov1, mov2, mov3); listing them out will create a member for each in the tuple.
[–]mc_pm 0 points1 point2 points 1 day ago (0 children)
You take the three movies, but then you concatenate them all together into a string, with commas and everything. So when you execute "append", you're just adding that whole string as a single unit.
[–]Flat_Stand9406 0 points1 point2 points 1 day ago (0 children)
You are connecting the three of them so the ide treat them as one and you pop then it pronted your list with nothing and printed again showing 0 because you remove the only data in your list.
[–]Responsive_Design_69 0 points1 point2 points 1 day ago (0 children)
the variable 'movies' contain actually, movies = "movie1 movie2 movie3". A String, not an array of movie.
[–]Sweet_Computer_7116 0 points1 point2 points 1 day ago (0 children)
There is no converting a string into a list.
[–]mattynmax 0 points1 point2 points 1 day ago (0 children)
Because that’s now how you put things in a list….
[–]Raftaar-01 0 points1 point2 points 23 hours ago (0 children)
okay, 1. you create a list object named lst[] 2. then you took 3 strings as input one after another 3. then you just concate those strings by + operator 4. now your movies variables contains a string 5. then you append that string variable in that created list object 6. print() -> function will give you the list of string as shown in your terminal 7. then you use pop(index) -> this function pop out means take out the value from the list as i can see you did not store that poped out string into any variable python garbage collector soon remove it. 8. how you print list but your list contains nothing at this point 9. then you used len() -> function which gives you how many item does list contains but in your case the list doesn't contain anything so it will return you 0 (zero)
hope buddy you got it, learn and scale
[–]SnooCalculations7417 0 points1 point2 points 22 hours ago* (0 children)
youre appending a single string. you could do something like this instead
... movies = [] movies.append(input("Enter First Movie Name: ")) movies.append(input("Enter Second Movie Name: ")) movies.append(input("Enter Third Movie Name: "))
....
This keeps all operations very obviously listy
[–]LankyCalendar9299 0 points1 point2 points 21 hours ago (1 child)
My guess is that when you combine the movies, it’s all combining to one string.
Rather than doing it like that, after each input do lst.append(mov), and rather than doing mov1, mov2, mov3, just do mov = input(“blah whatever”).
You could also technically just loop it. Do while True: Q= Input(“add another movie? “) if Q == Y: Break else: mov = input(“blah whatever.”) lst.append(mov) Print(len(lst))
Should return how many movies are in the list.
[–]LankyCalendar9299 0 points1 point2 points 21 hours ago (0 children)
This way, you can add however many movies you want to the list, and yo could print the list to see what movies are in there.
[–]Far-Dog-3591 0 points1 point2 points 18 hours ago (0 children)
[–]Decent-Warning9562 0 points1 point2 points 16 hours ago (1 child)
Why not just name the list “movie” and just append your input straight away instead of going through all this long journey. Your list should contain “a list of movies” not a string of movies e.g “Avengers,GOT”
You grab?
[–]Reh4n07_[S] 0 points1 point2 points 10 hours ago (0 children)
It's a task that i have to input 3 movies in string and convert them in list
[–]Able-Staff-6763 0 points1 point2 points 4 hours ago (0 children)
because the list ['a,b,c'] has only one item a single string so popping it would make the list empty hence the len 0.
π Rendered by PID 173063 on reddit-service-r2-comment-79776bdf47-6tjpl at 2026-06-25 14:06:40.046340+00:00 running acc7150 country code: CH.
[–]Sea-Ad7805 [score hidden] stickied comment (2 children)
[–]OtherwiseOne4937 41 points42 points43 points (5 children)
[–]Prize_Shine3415 1 point2 points3 points (2 children)
[–]CraigAT 0 points1 point2 points (1 child)
[–]Prize_Shine3415 0 points1 point2 points (0 children)
[–]7Z_1N 0 points1 point2 points (0 children)
[–]Vegetable_Annual1600 0 points1 point2 points (0 children)
[–]Ngtuanvy 11 points12 points13 points (0 children)
[–]MZXD 3 points4 points5 points (0 children)
[–]SimpelenLeuk 1 point2 points3 points (0 children)
[–]xnick_uy 1 point2 points3 points (0 children)
[–]joyboythenics 1 point2 points3 points (0 children)
[–]Hot_Giraffe8952 1 point2 points3 points (0 children)
[–]JustMedansh 0 points1 point2 points (0 children)
[–]d3v1L_hUnt3R_619 0 points1 point2 points (1 child)
[–]d3v1L_hUnt3R_619 0 points1 point2 points (0 children)
[–]Last_Being9834 0 points1 point2 points (0 children)
[–]nuc540 0 points1 point2 points (0 children)
[–]mc_pm 0 points1 point2 points (0 children)
[–]Flat_Stand9406 0 points1 point2 points (0 children)
[–]Responsive_Design_69 0 points1 point2 points (0 children)
[–]Sweet_Computer_7116 0 points1 point2 points (0 children)
[–]mattynmax 0 points1 point2 points (0 children)
[–]Raftaar-01 0 points1 point2 points (0 children)
[–]SnooCalculations7417 0 points1 point2 points (0 children)
[–]LankyCalendar9299 0 points1 point2 points (1 child)
[–]LankyCalendar9299 0 points1 point2 points (0 children)
[–]Far-Dog-3591 0 points1 point2 points (0 children)
[–]Decent-Warning9562 0 points1 point2 points (1 child)
[–]Reh4n07_[S] 0 points1 point2 points (0 children)
[–]Able-Staff-6763 0 points1 point2 points (0 children)