There is an ordered set (possible new link) recipe for this which is referred to from the Python 2 Documentation. This runs 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 Posts:
- Append values to a set in Python
- Does Python have an ordered set?
- Python set to list
- How to sort a set in python?
- Empty set literal?
- Add list to set?
- Creating 2D dictionary in Python
- Python Sets vs Lists
- In Python, when to use a Dictionary, List or Set?
- How to get all subsets of a set? (powerset)
- Type error Unhashable type:set
- How to make a set of lists
- TypeError: ‘set’ object does not support indexing
- Python Set Comprehension
- How do I add two sets?
- set object is not JSON serializable
- Get difference between two lists
- Converting a list to a set changes element order
- ImportError: DLL load failed: The specified module could not be found
- Replacements for switch statement in Python?
- Correct way to write line to file?
- How to read a file line-by-line into a list?
- How do I sort a dictionary by value?
- TypeError: only size-1 arrays can be converted to Python scalars (matplotlib)
- “Defaulting to user installation because normal site-packages is not writeable” python message
- How to install pytorch in Anaconda with conda or pip?
- How can I remove a key from a Python dictionary?
- What does numpy.random.seed(0) do?
- How do I check if a variable exists?
- Is there a label/goto in Python?
- Why do I get “Pickle – EOFError: Ran out of input” reading an empty file?
- Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries
- Python Pandas Counting the Occurrences of a Specific value
- What does the c underscore expression `c_` do exactly?
- Count unique values per groups with Pandas
- Get unique values from a list in python [duplicate]
- How do you decode Base64 data in Python?
- Convert pandas Series to DataFrame
- TypeError: ‘type’ object is not subscriptable when indexing in to a dictionary
- Error: all the input array dimensions except for the concatenation axis must match exactly
- Expected 2D array, got 1D array instead error
- How can I upgrade NumPy?
- How to get element-wise matrix multiplication (Hadamard product) in numpy?
- Matplotlib automatic legend outside plot
- Why am I getting this syntax error: keyword can’t be an expression
- Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty
- What is dtype(‘O’), in pandas?
- ctypes – Beginner
- Keras, how do I predict after I trained a model?
- How do I find out my PYTHONPATH using Python?
- ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224)
- Overflow Error in Python’s numpy.exp function
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock
- Catch multiple exceptions in one line (except block)
- Can’t broadcast input array from shape (3,1) into shape (3,)
- How to create an array of bits in Python?
- Setting Django up to use MySQL
- How can I check for NaN values?
- Python – how to use the constant e^
- Check if two unordered lists are equal
- Multiple assignment and evaluation order in Python
- deleting rows in numpy array
- How to make a 3D scatter plot in matplotlib
- Is there a list of Pytz Timezones?
- Flask example with POST
- How do I change the figure size with subplots?
- Clear terminal in Python [duplicate]
- ModuleNotFoundError: No module named ‘discord’
- No numeric types to aggregate – change in groupby() behaviour?
- ImportError: No module named six
- Easy pretty printing of floats?
- Algorithm for solving Sudoku
- How to read pickle file?
- pandas groupby sort within groups
- Python Socket Receive Large Amount of Data
- What is a “slug” in Django?
- Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll
- if else function in pandas dataframe
- Primality test in python [duplicate]
- Flask-SQLalchemy update a row’s information
- TypeError: Image data can not convert to float
- coercing to Unicode: need string or buffer, NoneType found when rendering in django admin
- Convert from ASCII string encoded in Hex to plain ASCII?
- Simple way to create matrix of random numbers
- pandas: multiple conditions while indexing data frame – unexpected behavior
- ‘instancemethod’ object has no attribute ‘__getitem__’ with class variables
- Python/Scikit-Learn – Can’t handle mix of multiclass and continuous
- Sorting list of lists by the first element of each sub-list
- Install py2exe for python 2.7 over pip: this package requires Python 3.3 or later
- python-How to set global variables in Flask?
- How do I install pip on macOS or OS X?
- NameError: name ‘get_ipython’ is not defined
- Equivalent to matlab’s imagesc in matplotlib? [duplicate]
- bash: syntax error near unexpected token `(‘ – Python
- Find all files in a directory with extension .txt in Python
- “public” or “private” attribute in Python ? What is the best way?
- How to search for a string in text files?
- TypeError: ‘zip’ object is not subscriptable
- Pip: could not find a version. No matching distribution found
- Compare two columns using pandas