Does Python have an ordered set?

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

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

14条回答
  •  甜味超标
    2020-11-21 13:52

    In case you're already using pandas in your code, its Index object behaves pretty like an ordered set, as shown in this article.

    Examples from the article:

    indA = pd.Index([1, 3, 5, 7, 9])
    indB = pd.Index([2, 3, 5, 7, 11])
    
    indA & indB  # intersection
    indA | indB  # union
    indA - indB  # difference
    indA ^ indB  # symmetric difference
    

提交回复
热议问题