LH10 added iterator

This commit is contained in:
K 2024-02-17 18:39:00 +05:30
parent 27069b283c
commit c33f887e27
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F

View File

@ -54,6 +54,12 @@ def intersection(setA, setB):
intersectionSet.append(i) intersectionSet.append(i)
print(f"Intersection is:\t{intersectionSet}") print(f"Intersection is:\t{intersectionSet}")
def iterator(setA):
a = iter(setA)
for i in range(0,len(setA)-1):
print(next(a),"->",end=' ')
print(next(a))
def union(setA, setB): def union(setA, setB):
# Function to perform union of two sets # Function to perform union of two sets
unionSet = [] unionSet = []
@ -136,7 +142,14 @@ def main():
else: else:
print("\nPlease choose a valid option.\n") print("\nPlease choose a valid option.\n")
elif (optn == 5): elif (optn == 5):
print("\nIMPLEMENTATION PENDING\n") setSel = int(input("Which set to operate on?\n1. Set one\n2. Set two\nSet 1/2:\t"))
a = None
if (setSel == 1):
iterator(setOne)
elif (setSel == 2):
iterator(setTwo)
else:
print("\nPlease choose a valid option.\n")
elif (optn == 6): elif (optn == 6):
intersection(setOne, setTwo) intersection(setOne, setTwo)
elif (optn == 7): elif (optn == 7):
@ -152,4 +165,4 @@ def main():
print("Please choose a valid option (1-10).") print("Please choose a valid option (1-10).")
main() # Calling the main function main() # Calling the main function
# END OF CODE # END OF CODE