Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Managerial Accounting

Authors: Ray H. Garrison, Eric W. Noreen, Peter C. Brewer

13th Edition

978-0073379616, 73379611, 978-0697789938

More Books

Students also viewed these Accounting questions