-1

i only get None after running random.shuffle in python

a = [(6, 7), (6, 5), (7, 4), (4, 4), (9, 8)]
print(f'{a=}')
x = random.shuffle(a)
print(f'{x=}')

>>> a = [(6, 7), (6, 5), (7, 4), (4, 4), (9, 8)]
>>> None
H Sa
  • 128
  • 9
  • 3
    From [docs](https://docs.python.org/3/library/random.html#random.shuffle). "Shuffle the sequence x in place." Therefore you don't need to assign `x` to `random.shuffle(a)`. And can simply shuffle inplace. – Jacques Jul 14 '21 at 11:55
  • That means ```random.shuffle``` is an inplace function. No nned to assign its value as it will return None of not return anything –  Jul 14 '21 at 11:56

1 Answers1

1

From docs:

random.shuffle(x[, random])

Shuffle the sequence x in place.

Therefore you don't need to assign x to random.shuffle(a). And can simply shuffle inplace.

a = [(6, 7), (6, 5), (7, 4), (4, 4), (9, 8)]
random.shuffle(a)
Jacques
  • 927
  • 9
  • 18