Completed: Yes Created: March 3, 2023 Tag: Python MOC
Unordered Objects In Python
- Unordered object don’t have an index for their elements, this means that you can not slice or index them.
- Unordered object don’t allow the repetition of elements
In Python, there are two built-in unordered collection objects:
- Sets: A set is an unordered collection of unique elements. Sets are defined using curly braces
{}or theset()constructor. For example:
my_set = {1, 2, 3}- Dictionaries: A dictionary is an unordered collection of key-value pairs. Dictionaries are defined using curly braces
{}with key-value pairs separated by colons:. For example:
my_dict = {"key1": "value1", "key2": "value2"}In addition to these built-in objects, Python also has several third-party libraries that provide additional unordered collection objects, such as defaultdict, Counter, and OrderedDict from the collections module.