Shuffle a deque

I am having trouble understanding how to shuffle a deque. let say I have these two deques (weather order or not ) and want to shuffle them. Why I am getting none here.

import random
from collections import deque

a = deque([1, 2, 3])
b = deque([4, 5, 6])

a += b

print(random.shuffle(a))


output:
None

Shuffle mutates passed argument in place, does not return shuffled result.

Example taken from w3s:

import random

mylist = ["apple", "banana", "cherry"]
random.shuffle(mylist)

print(mylist)

Python documentation says:

To shuffle an immutable sequence and return a new shuffled list, use sample(x, k=len(x)) instead.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.