I feel like an idiot for even asking this but does anyone have any idea why my code is printing the list after every shuffle?
def shuffle(L, nswaps):
n = 0
for item in L:
while n < nswaps:
card_one = choose(L)
card_two = choose(L)
if card_two == card_one:
card_two = choose(L)
n += 1
L[card_one], L[card_two] = L[card_two], L[card_one]
print L
NB I haven’t pasted the import/ calling the function stuff as it’s not relevant to the question.
Be careful with your indents:
Notice that the
print Lstatement is in the same level as the contents of theforloop (which is why it is called each time you loop).Delete four spaces from the whitespace preceding the
print Land all should go well.