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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!