Python Forum

Full Version: Set Output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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'}
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.