0

How do I assign a random element from list A without repeating it, to list a random element in list B, also without repeating it

25th May 2020, 1:16 PM
Kirill
Kirill - avatar
8 RĂ©ponses
25th May 2020, 2:29 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 2
You could shuffle list A, then just iterate through the list. Shuffle rearranges a list in a random order, so it would essentially be getting a random name each time. list A = [“Jake”, “Sam”] A.shuffle() for name in A: print(f”{name} is the name”) or something similar to that ^^
25th May 2020, 2:27 PM
Jax
Jax - avatar
+ 1
Kuba SiekierzyƄski thank you so much, just what I was looking for
25th May 2020, 2:31 PM
Kirill
Kirill - avatar
0
Use random.choice method.
25th May 2020, 1:52 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
0
Kuba SiekierzyƄski i tried that, but it will repeat the same elements
25th May 2020, 1:53 PM
Kirill
Kirill - avatar
0
If you just want to make list B with the same elements as list A, but in a different order, use .shuffle instead
25th May 2020, 1:55 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
0
Kuba SiekierzyƄski no, for example i have list A = [ "Jake", "Sam"] and then I have a list B = ["good", "bad"] and I want it to randomly print that jake or same is bad or good multiple times without repeating the names (in the actual list there are 8 names)
25th May 2020, 2:00 PM
Kirill
Kirill - avatar
0
Jax not exactly what I was looking for, but thanks for taking your time, fortunately someone has solved my problem
25th May 2020, 2:32 PM
Kirill
Kirill - avatar