Here's some code for shuffling a deck of cards manually. I understand it up to the point where cards[pos], cards[randpos] = cards[randpos], cards[pos]
. What is happening here? What is the point of assigning cards[pos] to cards[randpos]?
self.cards is a list of playing cards in standard order.
def shuffle(self):
n = len(self.cards)
cards = self.cards
for pos in range(n):
randpos = randrange(pos,n)
cards[pos], cards[randpos] = cards[randpos], cards[pos]