Does Python have an ordered set?

前端 未结 14 1338
予麋鹿
予麋鹿 2020-11-21 13:20

Python has an ordered dictionary. What about an ordered set?

14条回答
  •  一向
    一向 (楼主)
    2020-11-21 13:37

    So i also had a small list where i clearly had the possibility of introducing non-unique values.

    I searched for the existence of a unique list of some sort, but then realized that testing the existence of the element before adding it works just fine.

    if(not new_element in my_list):
        my_list.append(new_element)
    

    I don't know if there are caveats to this simple approach, but it solves my problem.

提交回复
热议问题