0 votes
1 view
in Python by (47.8k points)

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

1 Answer

0 votes
by (107k points)

Yes, python has an ordered set and they run on Py2.6 or later and 3.0 or later without any modifications. The interface is almost exactly the same as a normal set, except that initialisation should be done with a list.

OrderedSet([1, 2, 3])

This is a MutableSet, so the signature for .union doesn't match that of set, but since it includes __or__ something similar can easily be added:

@staticmethod 

def union(*sets): 

   union = OrderedSet() 

   union.union(*sets) 

   return union 

def union(self, *sets):

   for set in sets: 

       self |= set

Related questions

0 votes
1 answer
0 votes
2 answers
asked Oct 3, 2019 in Python by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 22, 2019 in Python by Eresh Kumar (32.3k points)
0 votes
1 answer
asked Aug 15, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer
asked Apr 9 in BI by Anup (1.6k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...