Ordered Vs Unordered In Python - DEV Community ‍ ‍

Add reaction Like Unicorn Exploding Head Raised Hands Fire Jump to Comments Save Boost More... Copy link Copy link Copied to Clipboard Share to X Share to LinkedIn Share to Facebook Share to Mastodon Share Post via... Report Abuse

There are different types of data structures in Python such as lists, tuples, dictionaries, and more.

Lists

It is a collection of a mutable ordered sequence of elements and can be accessed through indexing and defined inside []. Each element inside the list is called an item.

List Example

From the above image, it is clearly seen that list remembers the order of insertion or follows a sequence in which elements are inserted.

Tuples

It is a collection of ordered and immutable elements. Tuples are sequences, just like lists. It is defined inside () and can be accessed through indexing.

Alt Text

The above image shows that the tuple is ordered data structure and follows the insertion sequence.

Dictionary

It is a collection in which items are defined in key-value pairs inside {}. These items are unordered, changeable, and value is accessed through the particular key. Each key is separated from its value by a colon (:), the items are separated by commas. Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples.

Alt Text

In the above image, the order of insertion and output of the dictionary is different but what remains the same is the mapping of values with keys as the positioning might vary.

In the dictionary, we don't access items based on position unlike in lists and tuples but through keys.

pic Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Submit Preview Dismiss Code of Conduct Report abuse

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.

Hide child comments as well

Confirm

For further actions, you may consider blocking this person and/or reporting abuse

Oshi Gupta Follow Oshi Gupta works as a DevOps Engineer and Technical Writer at CloudYuga Technologies. She is CKA certified and has been selected for LFX mentorship in Spring 2022 for CNCF Kyverno.
  • Location Indore
  • Education Symbiosis University Of Applied Sciences
  • Work DevOps Engineer & Technical Writer at CloudYuga Technologies
  • Joined Feb 18, 2020
Git & Github Commands #github #git #beginners #codenewbie
DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

Tag » What Does Unordered Mean In Python