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 # 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)] (wo limes. # # 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 # you should try it out once so you'll remember how to use it. # -

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In Python, I need the answer will rate you

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
Transcribed Image 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education