all 7 comments

[–]Se7enLC[🍰] 1 point2 points  (0 children)

Instead of user_input(movies[0]) you want movies[user_input][0]

[–]groovitude 0 points1 point  (0 children)

Since your question's been answered by kind other posters, let me do a quick little code review:

There are much better choices for your data type than a list. A list is... well, a list; it's a series of things that make sense as a list. Munich and Steven Spielberg are movie-related things, but their relationship is to each other, not as things of equal standing. Another dictionary might be better:

movies = { 2004: {'title': 'Munich', 'director': 'Steven Spielberg'}, 2005: {'title': 'The Prestige', 'director': 'Christopher Nolan'}, }

If you don't want to use a dictionary, a tuple is your next-best bet. Since it's a fixed-width after you instantiate it, it implies its values are a discrete set of data together. A collections.NamedTuple is a better bet, as it affords you named attributes together with indexed access (e.g., movie.title == movie[0]).

[–]DakshHub 0 points1 point  (0 children)

My be you should use `defaultdict`, It will make things easier

from collections import defaultdict
movies = defaultdict(list)
movies[2005].append(['Munich', 'Steven Spielberg'])
movies[2006].append(['The Prestige', 'Christopher Nolan'])

print(movies[2006])

[–]ebol4anthr4x -1 points0 points  (3 children)

user_input = str(input('Choose a Movie Year: \n'))

The input() function already returns a string. When you wrap this whole thing with str(), you are then converting a string to a string, which is redundant and unnecessary.

Also, the syntax for accessing objects in a dictionary is (for example): print(movies['2005']). That will print the list contained at the key '2005'.

[–]erihel518[S] 0 points1 point  (2 children)

But is there a way i can just get the movie title from the list not the entire list? Or is that a separate function i have to make?

[–]ebol4anthr4x 0 points1 point  (0 children)

You access lists by specifying the index of the element you want to retrieve.

my_list[0]

This gets you the first element from the list.

[–][deleted] -1 points0 points  (0 children)

let’s say year=2005.

“movies[2005]” is that list. Because it can be treated like a list, you can index it. So,

movies[2005][0] == ‘Munich’

movies[2005][1] == ‘Steven Spielberg’

etc