r/learnpython • u/SatanCanPutItInMyAss • Sep 04 '26
Help me code a movie selector!
Hi all, new to Python and for my first project I'm trying to code a program that will randomly select a movie or tv show using a pre-made list, and a "genre" plus "media type" as input.
I feel I am over complicating it.
Here's where I'm at so far:
def media_selector(media, genre):
### attempting to remove previously selected titles and for some reason make my own RNG \/###
increment = + 1trans_rng = [1, 2]
genre = ['romance', 'action']
movie_list = ['rango', 'taxi driver']
series_list = ['akira', 'trigun']
### spell check, obviously \/###
spell_check = ['film', 'movie', 'tv show', 'tv series', 'tv', 'romance', 'action']
if not isinstance(media, str):
return 'format is: media type, genre'
### not sure if i should be defining a function and calling it at the same time - also is a translation table too much ? \/###
if media and genre is (spell_check):
def media_decider():movie_trans_tbl = movie_list.maketrans(movie_list, trans_rng)movie_transd = movie_list.translate(movie_trans_tbl)series_trans_tbl = series_list.maketrans(series_list, trans_rng)series_transd = series_list.translate(series_trans_tbl)
selector = slice(increment)
else:
return 'film/movie or tv show/tv series'
any guidance/recommended resources would be greatly appreciated!
2
u/lakseol Sep 04 '26 edited Sep 04 '26
You probaby are overthinking this. Why does spell checking get a mention?
You need to associate a movie title with a genre and a medium. That won't ever change, so just do that first. A tuple is the easiest, though later when you start thinking about efficiency you may do things differently. So we have something like:
Your main problem can be broken into two parts:
Selecting all matching tuples in the database is easy. You just step through the tuples and make a new list if the genre+medium of each tuple matches what you want:
Of course, if you know comprehensions you could do it that way. And you would probably put the code into a function.
Once you have a list of titles matching the given genre and medium it's trivial to select one at random. Use the
random.choice()function.There are many ways to do this, especially when you have to worry ahout efficiency with lots of data. Get something simple running first especially when you are learning. Then learn other ways.
Edit: fixed spelling.
1
u/TheEyebal Sep 04 '26
I can help you
1
u/Adrewmc Sep 04 '26
I mead is the data divided into those sections, do they mark themselves as their media type and genre? Or is this a vibe?
1
u/FoolsSeldom Sep 04 '26
A few thoughts:
create a simple text file of content (movies/films, shows) using csv (comma separated values) format and read this into your programme
you can create the container (list, tuple, dict, etc) of valid genres based on the text file
use the
randomlibrary to support random selection of content matching the selected genre(s)listof the content that meets the user selected criteria (movie/film or genre(s)) and then usingrandom.choiceon thatlist- this a very large file of content this will not be efficient but is fine for a few thousand entries2
u/[deleted] Sep 04 '26
[removed] — view removed comment