Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Permutations of r objects from a set of n unique objects is defined as all possible orderings of the subsets of size r from this

Permutations of r objects from a set of n unique objects is defined as all possible orderings of
the subsets of size r from this set. Implement a function permutations, which takes an array L (which can be a list, a
tuple or a string), and returns a listof-tuples containing all permutations of size 3 from its elements. You can assume
that the array L contains no repetitions (i.e., all elements are unique).
Here are sample runs for the expected return from the permutations function.
In [1]: L =[0,1,2,3]; out = permutations(L); print(out)
[(0,1,2),(0,1,3),(0,2,1),(0,2,3),(0,3,1),(0,3,2),(1,0,2),(1,0,3),(1,2,0),(1,2,3),(1,3,0),(1,3,2),(2,0,1),(2,
0,3),(2,1,0),(2,1,3),(2,3,0),(2,3,1),(3,0,1),(3,0,2),(3,1,0),(3,1,2),(3,2,0),(3,2,1)]
In [2]: L = "bric"; out = permutations(L); print(out)
[('b','r','i'),('b','r','c'),('b','i','r'),('b','i','c'),('b','c','r'),('b','c','i'),('r','b','i'),('r','b','c'),('r','i','b'),('r','i','c'),('r',
'c','b'),('r','c','i'),('i','b','r'),('i','b','c'),('i','r','b'),('i','r','c'),('i','c','b'),('i','c','r'),('c','b','r'),('c','b','i'),('c','r','b'),
('c','r','i'),('c','i','b'),('c','i','r')]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions