Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set Output
#1
Hi i am running below code
color_list_1 = set(["White", "Black", "Red"])
color_list_2 = set(["Red", "Green"])

for i in color_list_1:
    if i not in color_list_2:
        print(i)
        
print(color_list_1.difference(color_list_2))
print(color_list_1-color_list_2)
oddly the results were printing reversed and automatically was corrected

Black
White
{'Black', 'White'}
>>> %Run ListCompare.py
White
Black
{'White', 'Black'}
>>> %Run ListCompare.py
White
Black
{'White', 'Black'}
{'White', 'Black'}
>>> %Run ListCompare.py
White
Black
{'White', 'Black'}
{'White', 'Black'}
Reply
#2
You don't ask a question, so guessing you want to know why. Sets are unordered collections of unique objects. Unordered means you cannot count on the order.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020