Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Build a code using python


See attAched for better viewComplete build 3. Use Builds 1 and 2 to help with code for build. You do not have to complete 1 and 2. ONLY 3.Assignment 6As usual, the parts of this assignment are worth equal amounts. This assignment brings together Python and sets that were covered in the Math. You will probably be helped by drawing some of the sets1. Build 1Build 1 Part A: Known issuesHere is the introduction to the program:”’INTENT: Produce all partitions of a setEXAMPLE: A teacher wants to partition her (small) class consisting of Adam, Carlene, and Frank,to create study groups. Find the possible ways to do this, each partition being a list of lists.The output would be as follows (though not necessarily on separate lines):[[Adam, Carlene, Frank]] — a list consisting of just one list[[Adam], [Carlene, Frank]][[Adam, Carlene], [Frank]][[Adam, Frank], [Carline]] [[Adam], [Carlene], [Frank]] — a list consisting of three simple listsKNOWN ISSUES: Used lists but order is irrelevant.”’In software development, a “known issue” is one that the developer is aware of, could not attend to, and notes for subsequent work as a professional obligation. They are not considered serious at this stage, and they often refer to clear improvements. In 1 or 2 sentences, explain why and how the one above is indeed an issue.Build 1 Part B: Program decomposition +Consider the (helper) function extend_partitions() given below. You are not being asked to code for this part of the assignment, just answer questions about the function.(a) Using the documentation supplied as comments in the code, explain why the postcondition is fulfilled. You can assume that each code block fulfils its stated objectives.For example, below is the objective (the desired outcome) of the first code block. The part in parentheses (Excluding [a_new_element]): is a label for the objective so you can get an idea of what it’s about before reading the details. Notice that there is a difference between simply an element such as ‘hi’ and the list consisting of the element such as [‘hi’]. # (Excluding [a_new_element]): returned_partition includes all partitions # of (S union {a_new_element}) that don’t contain the list [a_new_element](b) Explain why deepcopy() was used rather than just copy(). You may need to do a bit of research.import copydef extend_partitions(some_partitions, a_new_element): ”’ Preconditions: 1. some_partitions consists of partition of a set S (which need not be specified!) in the form of a list of lists of the set’s elements. Example: S = {0, 11}, some_partitions = [[[0, 11]], [[0], [11]]] 2. a_new_element does not occur in some_partitions Returns: returned_partitions = all partitions of (S union {a_new_element}) Example: for S = {0, 11} and a_new_element = 22, this returns the following list (containing 5 elements): [[[0, 11, 22]], [[0, 22], [11]], [[0], [11, 22]], [[0, 11], [22]], [[0], [11], [22]]] ”’ returned_partitions = [] # (Excluding [a_new_element]): returned_partition includes all partitions # of (S union {a_new_element}) that don’t contain the list [a_new_element] # Example: For S = {0, 11} and a_new_element = 22, returned_partitions would include # [[0, 11, 22]], [[0, 22], [11]], [[0], [11, 22]], and [[[0], [11]], 22]]] # (notice that none of these partitions contains [22]) for _partition in some_partitions: # e.g., _partition = [[0], [11]] for i in range(len(_partition)): # e.g., i points to [0] new_partition = copy.deepcopy(_partition) new_partition[i].append(a_new_element) # e.g., get [[0, 22], [11]] returned_partitions.append(new_partition) # (Including [a_new_element]): returned_partition includes all partitions # of S union {a_new_element} that contain [a_new_element] # e.g., For the example above, returned_partition includes # [[0, 11], [22]] and [[0], [11], [22]]] for _partition in some_partitions: # e.g., [[0, 11]] appended_partition = copy.deepcopy(_partition) appended_partition.append([a_new_element]) returned_partitions.append(appended_partition) # e.g., append [[0, 11], [22]] in the example return returned_partitions2. Build 2: TestsHere is a test for extend_partitions(). It prints an application of extend_partitions() to particular parameters, and then prints what the output should be. The user can compare these to be sure that the function is operating as specified by its postconditions.# TESTS =========================================# OF extend_partitions() ============print(extend_partitions([[[0],[11]]], 22))print(“[[[0, 22], [11]], [[0], [11, 22]], [[0], [11], [22]]]n”)Provide two additional tests for extend_partitions() in the same form as this one. 3. Build 3: Writing your code complete this sectionUse extend_partitions() (cut and paste it) to write the following function.def all_partitions_of(a_list): ”’ Precondition: a_list is any list Returns returned_partitions = a list of all partitions of a_list} Example: for a_list = [0, 11, 22], this function returns [[[0, 11, 22]], [[0, 22], [11]], [[0], [11, 22]], [[0, 11], [22]], [[0], [11], [22]]] ”’You may need the following kind of operation:Here is the algorithm breakdown that I used.# (Trivial?): EITHER a_list has >1 element # OR a_list has <2 elements and this returned# and returned_partitions = the list of all partitions of a_list … 2 lines of code …Here is the next objective I fulfilled, complete with code:# (i): 0 < i <= len(a_list) AND# returned_partitions = the list of all partitions of a_list[:i]i, returned_partitions = 1, [[[a_list[0]]]]Here is the last objective:# i >= len(a_list)… code … My code is a while loop with two lines within it, and it uses the helper function extend_partitions().Conclude the code with the following line:return returned_partitionsHere is why the stated objectives are sufficient: if the execution makes it to the end, you can conclude … a_list has >1 element AND0 < i <= len(a_list) ANDreturned_partitions = the list of all partitions of a_list[:i]AND# i >= len(a_list)so …returned_partitions = the list of all partitions of a_listHere are tests that you can use to validate your code:# OF all_partitions_of() ===========print(“[[[]]]<–>” + str(all_partitions_of([])) + ‘n’) # one list–consisting of []print(“[[[333]]]<–>” + str(all_partitions_of([333])) + ‘n’)print(‘all_partitions_of([0,22]):’)print(all_partitions_of([0,22]))print(“[[[0, 22]], [[0], [22]]]n”)print(‘all_partitions_of([0,11,22]):’)print(all_partitions_of([0,11,22]))print(“[[[0, 22], [11]], [[0], [11, 22]], [[0, 11, 22]], [[0], [11], [22]], [[0, 11], [22]]]n”)print(‘all_partitions_of([0,11,22,33]):’)print(all_partitions_of([0,11,22,33]))print(‘all_partitions_of([7,8,1,3,5]):’)print(all_partitions_of([7,8,1,3,5]))When running module the come should look like this:The last of these tests produces the following:all_partitions_of([7,8,1,3,5]):[[[7, 8, 1, 3, 5]], [[7, 1, 3, 5], [8]], [[7, 1, 3], [8, 5]], [[7, 1, 5], [8, 3]], [[7, 1], [8, 3, 5]], [[7, 3, 5], [8, 1]], [[7, 3], [8, 1, 5]], [[7, 5], [8, 1, 3]], [[7], [8, 1, 3, 5]], [[7, 8, 3, 5], [1]], [[7, 8, 3], [1, 5]], [[7, 8, 5], [1, 3]], [[7, 8], [1, 3, 5]], [[7, 3, 5], [8], [1]], [[7, 3], [8, 5], [1]], [[7, 3], [8], [1, 5]], [[7, 5], [8, 3], [1]], [[7], [8, 3, 5], [1]], [[7], [8, 3], [1, 5]], [[7, 5], [8], [1, 3]], [[7], [8, 5], [1, 3]], [[7], [8], [1, 3, 5]], [[7, 8, 1, 5], [3]], [[7, 8, 1], [3, 5]], [[7, 1, 5], [8], [3]], [[7, 1], [8, 5], [3]], [[7, 1], [8], [3, 5]], [[7, 5], [8, 1], [3]], [[7], [8, 1, 5], [3]], [[7], [8, 1], [3, 5]], [[7, 8, 5], [1], [3]], [[7, 8], [1, 5], [3]], [[7, 8], [1], [3, 5]], [[7, 5], [8], [1], [3]], [[7], [8, 5], [1], [3]], [[7], [8], [1, 5], [3]], [[7], [8], [1], [3, 5]], [[7, 8, 1, 3], [5]], [[7, 1, 3], [8], [5]], [[7, 1], [8, 3], [5]], [[7, 3], [8, 1], [5]], [[7], [8, 1, 3], [5]], [[7, 8, 3], [1], [5]], [[7, 8], [1, 3], [5]], [[7, 3], [8], [1], [5]], [[7], [8, 3], [1], [5]], [[7], [8], [1, 3], [5]], [[7, 8, 1], [3], [5]], [[7, 1], [8], [3], [5]], [[7], [8, 1], [3], [5]], [[7, 8], [1], [3], [5]], [[7], [8], [1], [3], [5]]]

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"