shuffled
The random module's shuffle
method mixes up (shuffles) the elements of a list in place, thus its return value is None
. Because of this we cannot contract several operations, so for instance we cannot express easily the following: "shuffle the elements of the list and then return with the last element" ( the following doesn't work: random.shuffle(list1)[-1]
).
Exercise
Create a function called shuffled
, which returns with the shuffled list, making an operation like this possible: shuffled(list1)[-1]
. Make sure that shuffled()
doesn't modify the original list! In this respect, it should be similar to sorted()
.