7. import random # -q7.py # Write a function permutation(L) which # returns a random permutation of L by the following method: # (0) initialize an empty list P and a copy of L: C = list(L) # (1) Use...


In Python, I need the answer will rate you


7.<br>import random<br>#<br>-q7.py<br># Write a function permutation(L) which<br># returns a random permutation of L by the following method:<br># (0) initialize an empty list P and a copy of L: C = list(L)<br># (1) Use random.randrange(0, len(C)) to get a random index, i<br># (2) remove element i from the list C using pop() and<br># (3) append that element to the new list P<br># (4) repeat steps (1-3) until all the elmeents are transferred from C to P<br># (5) return the new list P<br>I<br>#-<br># 1. Try your function on the sequence range(0, 30), which isn't a list,<br># but it should work anyway.<br># 2. Do thạt again to see that you get a new permuation.<br># 3. Try it on [19, 4, 3, 17] two times.<br># 4. Try it on poly - [(0, 0), (20, 0), (20, 10), (0, 10)] two times.<br>|<br># -<br># Note: Although the random package has a function that will<br># make a random permuation of a list L:<br># random.sample(L, len(L))<br># in this question you shouldn't use the sample() function, but<br>should try it out once so you'll remember how to use it.<br>#<br>you<br>%23<br>

Extracted text: 7. import random # -q7.py # Write a function permutation(L) which # returns a random permutation of L by the following method: # (0) initialize an empty list P and a copy of L: C = list(L) # (1) Use random.randrange(0, len(C)) to get a random index, i # (2) remove element i from the list C using pop() and # (3) append that element to the new list P # (4) repeat steps (1-3) until all the elmeents are transferred from C to P # (5) return the new list P I #- # 1. Try your function on the sequence range(0, 30), which isn't a list, # but it should work anyway. # 2. Do thạt again to see that you get a new permuation. # 3. Try it on [19, 4, 3, 17] two times. # 4. Try it on poly - [(0, 0), (20, 0), (20, 10), (0, 10)] two times. | # - # Note: Although the random package has a function that will # make a random permuation of a list L: # random.sample(L, len(L)) # in this question you shouldn't use the sample() function, but should try it out once so you'll remember how to use it. # you %23

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here