I make a list named scramble. This list is created by randomly adding the values of 2 lists (move1 and move2)
When I print the list, the answer are surrounded by " " or ''.
exemple :
scramble = ['U', 'F2', 'B', 'R2', "U'", 'R', "R'", 'D', 'L2', 'B2', "U'", 'R2', "R'", 'F', "D'"]
my code:
import random as rd
scramble = []
move1 = ["F","R","L","U","B","D"]
move2 = ["","'","2"]
while len(scramble) < 15:
s = move1[rd.randint(0, 5)]
t = move2[rd.randint(0, 2)]
scramble.append(s+t)
I really want to understand why it happens.
and then, correct it.
I suppose that they are several ways to clean the "" and '' after the list is created. But :
I finally found the solution. Well, I still don't know why printing the scramble list gave me a mix of " and ' but print(.joint) seems to work.
Thanks to everyone.
import random as rd
scramble = []
move1 = ["F","R","L","U","B","D"]
move2 = ["","'","2"]
# generate the first move to compare with the next ones :
s = rd.choice(move1)
t = rd.choice(move2)
scramble.append(s+t)
# generate the next 14 ones and do not tolerate the same "move1" next to each other (using "startswith" method):
for i in range(1,15):
n = len(scramble)
s = rd.choice(move1)
t = rd.choice(move2)
if scramble[n-1].startswith(s) :
pass
else :
scramble.append(s+t)
# show the result, with spaces
print(" ".join(scramble))