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
8 RĂ©ponses
+ 3
This is what I had on mind:
https://code.sololearn.com/cnEKt6Kjmxq7/?ref=app
+ 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 ^^
+ 1
Kuba SiekierzyĆski thank you so much, just what I was looking for
0
Use random.choice method.
0
Kuba SiekierzyĆski i tried that, but it will repeat the same elements
0
If you just want to make list B with the same elements as list A, but in a different order, use .shuffle instead
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)
0
Jax not exactly what I was looking for, but thanks for taking your time, fortunately someone has solved my problem