Difference between Lists, Dictionary, Tuples & Arrays in Python

Arrays vs Lists vs Dictionary, Tuples

I often find dictionaries, lists, tuples and arrays confusing as essentially they all are data structures in python and other programming languages such as JavaScript. I tried googling it but it I only found practical implementations for them. I found how to use them but for simple differences I had to search and read more content so if you are like me, keep reading for understanding simple key differences among them.

Lets start with definitions.

List

A list is a collection of items that are enclosed in square brackets. The items in a list are ordered and can be changed after the list is created. Lists are very versatile and can be used to store a wide variety of items, such as numbers, strings, other lists, etc. They are also very efficient for certain operations such as appending and removing items.

In simple words, a list is like a collection of items, where the items are ordered, and you can add, remove or change the items in the collection, it’s like a shopping list, you can add or remove items from it.

Dictionary

A dictionary is an unordered collection of items, enclosed in curly braces. Each item in a dictionary consists of a key-value pair, where the key is used to access the corresponding value. Dictionaries are very efficient for looking up values by their key, and are commonly used to store key-value pairs.

A dictionary is like a book where each word has a definition, where the word is the key and the definition is the value, it’s like a phonebook where you can look up a phone number by the name, you can add or remove items(key-value pairs) from it.

Array

An array is a data structure that is used to store a collection of items. The items stored in an array can be of any data type and the array is defined using the “array” module. The array is also ordered and indexed, which allows you to access specific elements by their position in the array.

An array is like a collection of items, where you can store different types of items, and the order of the items is important, and you can perform mathematical operations on the items, it’s mainly used in numerical computations. Arrays are mainly used when you need to perform mathematical operations on large data sets.

Tuple

A tuple is a collection of items that are enclosed in round brackets. The items in a tuple are ordered and cannot be changed once created. They are often used to group related data together, or to return multiple values from a function.

A tuple is like a package of items, where the items inside the package cannot be changed, but you can still access to them, a tuple is a simple way to group items together and store them in a single variable.

Key Points and Differences

Data StructureFeaturesPossibilitiesMost Common UsesDo’s and Don’ts
TuplesImmutable, Ordered, IndexedGrouping related data together, Returning multiple values from a function, Using in multiple variable assignmentsStoring elements of a database record, Storing a set of related values in a single variableDo use tuples when the data doesn’t need to be changed, Don’t use tuples when you need to add or remove elements
ListsMutable, Ordered, IndexedStoring a wide variety of items, Efficient appending and removing itemsStoring a collection of items, Creating a list of items for iterationDo use lists when you need to change the data, Don’t use lists when immutability is required
ArraysMutable, Ordered, IndexedStoring a collection of items, Efficient numerical computationsStoring a collection of items, Creating a list of items for iteration, Performing mathematical operations on large data setsDo use arrays when you need to perform mathematical operations on large data sets, Don’t use arrays when you need to store non-numerical data
DictionariesMutable, Unordered, Key-value pairsEfficient lookups by key, Storing key-value pairsStoring key-value pairs, Creating a dictionary of items for iteration, Storing data in key-value pairsDo use dictionaries when you need to store key-value pairs, Don’t use dictionaries when order is important