Question: I need to write a program based on two finished programs (listm.py and setunion.py) to implement the intersection operation between two sets of list. The

I need to write a program based on two finished programs (listm.py and setunion.py) to implement the intersection operation between two sets of list. The program should not use the Python built-in list and set related functions and operations. here is listm.py I need to write a program based on two finished programs (listm.py

here is setunion.py and setunion.py) to implement the intersection operation between two sets of list. I'm trying to finish it like this(modify setunion.py and open a new file called intersection.py): The program should not use the Python built-in list and set related but finally I get the result is: TypeError: 'List' object is not iterable

What's wrong with me?

Help File Edit Format Run Options Window Elass List: def __init__(self, extlist=None): if extlist is None: self.inlist = [] else: self.inlist = extlist def length(L): return len( L inlist) def is empty(L):... if len( L. inlist)==0): return True else: return False def get(L, i): if is empty(L): print("The get() is unsuccessful!") print("The list is empty!") return -1 elif (ilength(L)): print("The get() is unsuccessful!") print("The index given is out of range!") return -1 else: return( L. inlist[i-1]) def locatebyvalue(L, x): position = 1 for item in L. inlist: if x == item: return position else: position = position+1 return -1 def locatebyid(L, idd): position = 1 for item in L. inlist: if item.id == idd: return position else: position = position+1 return -1 def insert(L, i, x); if (ilength(L)+1): print("The insert() is unsuccessful!"). print("The index given is out of range!") else: L.inlist.insert(i-1, x) def delete(L, i): if is empty(L): print("The delete() is unsuccessful!") print("The list is empty!") return elif (ilength(L)): print("The delete() is unsuccessful!") print("The index given is out of range!") return else: del L. inlist[i-1] def display(L):. print(L. inlist) Ln: 1 Col: 0 File Edit Format Run Options Window Help from listan import * def un( seta, setB): n = length( seta) for i in range( length(setB)): x = get(sets, 1+1) k = locatebyvalue( seta, x) if (k==-1): insert(seta, n+1, x) n = n+1 seta = List([1, 2, 3, 4, 5]) setB - List(12, 4, 5, 10, 11]) display( setA) display( setB) un seta, setB) print("The union result is as follows") display( setA) Ln: 1 Col: 0 File Edit Format Run Options Window from listom import * from intersection import * def un( seta, setB): n = length( setA) for i in range(length( setB)): x = get(SetB, i+1) k = locatebyvalue( seta, x) if (k==-1): insert(seta, n+1, x) n = n+1 File Edit Format Run Options Window Help def intersection( seta, setb): setc=[] for nu in seta: if num in setb: setc.append(num) return setc setA = List([1, 2, 3, 4, 5]) setB = Listii2. 5. 10. 11 display( setA) display( setB) un( seta, setB) print("The union result is as follows") display( seta) print("The intersection is:"). print(intersection seta, setB)) Ln: 7 Col: 0 Help File Edit Format Run Options Window Elass List: def __init__(self, extlist=None): if extlist is None: self.inlist = [] else: self.inlist = extlist def length(L): return len( L inlist) def is empty(L):... if len( L. inlist)==0): return True else: return False def get(L, i): if is empty(L): print("The get() is unsuccessful!") print("The list is empty!") return -1 elif (ilength(L)): print("The get() is unsuccessful!") print("The index given is out of range!") return -1 else: return( L. inlist[i-1]) def locatebyvalue(L, x): position = 1 for item in L. inlist: if x == item: return position else: position = position+1 return -1 def locatebyid(L, idd): position = 1 for item in L. inlist: if item.id == idd: return position else: position = position+1 return -1 def insert(L, i, x); if (ilength(L)+1): print("The insert() is unsuccessful!"). print("The index given is out of range!") else: L.inlist.insert(i-1, x) def delete(L, i): if is empty(L): print("The delete() is unsuccessful!") print("The list is empty!") return elif (ilength(L)): print("The delete() is unsuccessful!") print("The index given is out of range!") return else: del L. inlist[i-1] def display(L):. print(L. inlist) Ln: 1 Col: 0 File Edit Format Run Options Window Help from listan import * def un( seta, setB): n = length( seta) for i in range( length(setB)): x = get(sets, 1+1) k = locatebyvalue( seta, x) if (k==-1): insert(seta, n+1, x) n = n+1 seta = List([1, 2, 3, 4, 5]) setB - List(12, 4, 5, 10, 11]) display( setA) display( setB) un seta, setB) print("The union result is as follows") display( setA) Ln: 1 Col: 0 File Edit Format Run Options Window from listom import * from intersection import * def un( seta, setB): n = length( setA) for i in range(length( setB)): x = get(SetB, i+1) k = locatebyvalue( seta, x) if (k==-1): insert(seta, n+1, x) n = n+1 File Edit Format Run Options Window Help def intersection( seta, setb): setc=[] for nu in seta: if num in setb: setc.append(num) return setc setA = List([1, 2, 3, 4, 5]) setB = Listii2. 5. 10. 11 display( setA) display( setB) un( seta, setB) print("The union result is as follows") display( seta) print("The intersection is:"). print(intersection seta, setB)) Ln: 7 Col: 0

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 Databases Questions!