Attention: Python Set is Changing From Time to Time

Hongtao Hao / 2022-08-12


I just learned this several days ago: set in python is unsorted and changes from time to time.

For example:

a = ['a', 'b', 'b', 'c', 'd', 'd', 'e']
set(a)

If you run the codes twice (in two different notebooks or scripts), the results are different. To solve this problem:

list(set(a)).sort()
#tutorial

Last modified on 2022-10-01