I need to use movies_list
from the first function in the second. How do I do that?
def movie():
movies_list = [movie.strip() for movie in movies
Use return
and arguments
def movie():
movies_list = [movie.strip() for movie in movies_list]
movie_explorer()
return movies_list
def rand(movies_list):
rand_item = print(random.choice(movies_list))
And when calling rand
remember to call the function as
rand(movie())
Add a line
global movies_list
as the first line in both functions
You can make use of the globals
object available. (Adding it here to complete the rhyme)
def movie():
global movie_returns
movie_returns = [movie.strip() for movie in movies_list]
movie_explorer()
# No return
def rand(): # No argument
movies_list = next((globals()[v] for v in globals() if v=='movies_return'))
rand_item = random.choice(movies_list)