I have a code that prints a list of the intersections from two sequences (even duplicates) (so I can't use set() function).
here is my code:
print("This program finds the intersection of two sets")
sequenceOne = input("Please enter the space-separated elements of the first set: ")
sequenceTwo = input("Please enter the space-separated elements of the second set: ")
sequenceOne = sequenceOne.split()
sequenceTwo = sequenceTwo.split()
listOfIntersection = []
for i in sequenceOne:
for j in sequenceTwo:
if i == j:
sequenceTwo.remove(i)
listOfIntersection.append(j)
print('{',(", ".join(str(i) for i in listOfIntersection)), '}')
for this code, I need to use nested loops, and the output needs to be between curly braces {}. the problem is in my output, its wrong and I don't know how to fix it.
My output:
Please enter the space-separated elements of the first set: 12 k e 34 1.5 12 hi 12 0.2
Please enter the space-separated elements of the second set: 1.5 hi 12 0.1 54 12 hi hi hi
The intersection of these two sets is { 12, 12, 1.5, hi, hi, hi }
desired output:
The intersection of these two sets is {12, 12, 1.5, hi}
Could you please help me with it?