Define Function Python Shuffle Seq Shuffle List Passed Using Following Algorithm Location Q37198344

define this function in python:

shuffle(seq): Shuffle the list passed in using the followingalgorithm: for each location in the list, swap the item at thatlocation with a random item from with itself of something furtherdown the list. This should work to shuffle any list (deck of cards,list of ints, etc.)

Example:  Let’s say you have a list: [‘cat’,’dog’,’fox’,’goat’] Start with the first item (‘cat’) and swap it with itself or arandom item later in the list.

 Let’s say you swap with ‘goat’, so you have a new list:[‘goat’,’dog’,’fox’,’cat’]  The second item is ‘dog’, so swap itwith itself or a random

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.