Question
PYTHON: Write a function that takes as argument a dictionary representing a permutation, and returns the list of closed sets of the permutation. def closed_sets(permutation):
PYTHON:
Write a function that takes as argument a dictionary representing a permutation, and returns the list of closed sets of the permutation.
def closed_sets(permutation):
#TODO: implement this function
That is:
p1 = { 'alice' : 'carol', 'bob' : 'bob', 'carol' : 'eve',
'dave' : 'dave', 'eve' : 'alice' }
should return:
[['alice', 'carol', 'eve'], ['bob'], ['dave']]
as 'bob' and 'dave' have key and value of themselves, so they are consider close set.
p2 = { 'alice' : 'bob', 'bob' : 'carol', 'carol' : 'dave',
'dave' : 'eve', 'eve' : 'alice' }
should return:
[['alice', 'bob', 'carol', 'dave', 'eve']]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started