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. # -
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
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F31b13744-2a7c-4c52-8a63-0a640293092a%2F5e1f76e5-b9d7-4f06-a50e-43f742bc6f1d%2Fe0ejos_processed.jpeg&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education