0

I want to shuffle some items in a list and display that while maintaining original list. Have no clue what to do (sorry I'm a beginner-ish)

import random

myList = ["apple", "banana", "cherry", "mango", "watermelon", "orange"]

newList = random.shuffle(myList)

print(myList)#want this to be original one
print(newList)#want this to be shuffled one
#but they both end up being shuffled
Ben Grossmann
  • 4,387
  • 1
  • 12
  • 16
  • Maybe take a `.copy()` of your list and shuffle that. Then you have both. Note at the moment `newlist` is `None` as `shuffle()` is in-place. – JonSG Feb 28 '22 at 22:26
  • @user The documentation on the random module recommends the following: `newList = random.sample(myList,k=len(myList))`. – Ben Grossmann Feb 28 '22 at 22:27

0 Answers0