-1

I am brand new to python, have never used it before but I'm working on a project for an operating systems class where I am supposed simulate process scheduling. I'm trying to use a generator, it has to be done with generator, to print these two lists I have come up with one a time randomly between 4-7 times. I can't figure out how to do it. I would appreciate some assistance or a point in the right direction. Here is all I have been able to figure out myself just looking around online.

movies = ["Blade Runnner", "Alien", "Mad Max", "The Fifth Element", "Princess Bride", "Escape from Alcatraz", "The Dark Knight"]
games = ["Dead Space", "Mass Effect 2", "Oblivion", "Bioshock", "Bad Comapny 2"]

for x, y in zip(movies, games):
print x,y 

This kind of does what I need it to do doesn't do it randomly. Ive been working for a couple of days now and have tried a bunch of stuff (including shuffle) that hasn't worked liked I need it to but this is in the right direction I feel like.

Michael
  • 1
  • 1

2 Answers2

0

You can use random.sample() to get a randomized version of each list before zip

from random import sample
for x, y in zip(sample(movies, len(movies)), sample(games, len(games))):
    print(x,'|',y)
G. Anderson
  • 5,815
  • 2
  • 14
  • 21
0

You could use random.choice

from random import choice

movies = ["Blade Runnner", "Alien", "Mad Max", "The Fifth Element", "Princess Bride", "Escape from Alcatraz", "The Dark Knight"]
games = ["Dead Space", "Mass Effect 2", "Oblivion", "Bioshock", "Bad Comapny 2"]


for i in range(10):
    print(choice(movies),choice(games))
Prayson W. Daniel
  • 14,191
  • 4
  • 51
  • 57