# Difference between List, Tuple, Set and Dictionary in Python

By Priyanshu Vaish|Updated : October 14th, 2022

Difference between List, Tuple, Set, and Dictionary in Python: List, Tuple, Set, and Dictionary are Python elements, but there is a key difference between list, tuple, set, and dictionary in Python. Here, we will first see the difference between List, Tuple, Set, and Dictionary in Python; then, we will discuss the List, Tuple, Set, and Dictionary individually.

Difference between List, Tuple, Set, and Dictionary in Python PDF

The basic difference between a list, tuple, set and dictionary in Python is that a list is a collection of data that has been ordered. A tuple is a data collection that is ordered. A set is a collection that is not ordered. A dictionary is an unsorted data collection that stores information in key-value pairs.

## Difference between List, Tuple, Set, and Dictionary in Python

The table shows the difference between List, Tuple, Set, and Dictionary in Python based on the representation, structure, etc. The difference between these elements of Python is essential for the GATE CSE exam as various concepts can be cleared using this.

Key Difference between List, Tuple, Set, and Dictionary in Python

 List Tuple Set Dictionary List is a non-homogeneous data structure that stores elements in single rows and multiple rows and columns. A tuple is a non-homogeneous data structure that can store a single row and multiple rows and columns. The set data structure is also non-homogeneous but only stores one row. A dictionary is another type of non-homogeneous data structure that stores key-value pairs. The list is represented by []. The tuple is represented by (). The set is represented by {}. The dictionary is represented by {}. Lists are mutable, which means they can be changed. The tuple is immutable, which means it cannot be changed. The set is mutable, which means that we can change it. However, no elements are duplicated. The dictionary is mutable. However, keys are not duplicated. The list is ordered. The tuple has been ordered. The set is unordered. The dictionary has been ordered (Python 3.7 and above) Lists can be nested among themselves. Tuple can make use of nested among all. Sets can be nested among themselves. All dictionaries can use nested among themselves.

## What is a List?

In Python, a list is a heterogeneous container for items. This is similar to an array in C++, but since Python does not support arrays, we have Python Lists instead. The list is an important part of the GATE CSE syllabus. To use a list, you must first declare it. Use square brackets to separate values and commas to separate them.

>> programming languages = ['C++, "Python, "Scratch']

A list can contain any type of value. This can be a string, a Tuple, a Boolean expression, or even a list.

>> list1=[1,[2,3],(4,5), False, 'No']

It's worth noting that we've included a variety of values in this list. As a result, a list is (or can be) heterogeneous.

## What is a Tuple?

This Python Data Structure is a heterogeneous container for items, similar to a list in Python. The main distinction between the two (tuple and list) is that a list is mutable, whereas a tuple is immutable. A tuple is This means that while an entire tuple can be reassigned or deleted, a single item or slice cannot.

We use parentheses to declare a tuple.

>>colors = ('Red', 'Green', 'Blue')

## What is Set?

This is an essential Python Data Structure. A Python set differs from a list or a tuple in some ways. In Python, a set is the same as a mathematical set. It is unordered and does not contain duplicate values. However, unlike a tuple, it is not immutable, and MSQ-based questions are formulated in the GATE question paper on this topic.

Let us begin by declaring a set. For the same effect, use curly braces.

>> myset=3,1,2

>> myset

Result:

{1, 2, 3}

## What is the Dictionary?

Finally, we will examine Python dictionaries. Consider a physical dictionary. What is its purpose? It contains pairs of word meanings and is important for the GATE exam. Similarly, the Python dictionary stores key-value pairs. You may not, however, use an unhashable item as a key. Curly braces are used to declare a Python dictionary.

However, the presence of key-value pairs rather than single values distinguishes a dictionary from a set.

>> mydict = {1:2, 2:4, 3:6}

Output:

{1: 2, 2: 4, 3: 6}

 Important Topics for Gate Exam Admixtures Truss Bolted Connection Dynamic Programming Difference Between Struts and Columns Design of Beams Polymers Huffman Coding Mechanical Properties of Engineering Materials Moulding Sand Crystal Defects Kruskal Algorithm Free body diagram Internal forces Influence line diagram Deflection of Beams Internal and external forces Principle of superposition of forces Losses of Prestress Moment Distribution Method

write a comment

## FAQs on Difference between List, Tuple, Set and Dictionary

• The basic difference between List, tuple, set and dictionary in python is that a list is a collection of data that has been ordered. A tuple is a data collection that is ordered. A set is a collection that is not ordered. A dictionary is an unsorted data collection that stores information in key-value pairs.

• The difference between List, tuple, set and dictionary in python regarding the representation is that the list is represented by []. The tuple is represented by (). The set is represented by {}. The dictionary is represented by {}.

• The difference between List, tuple, set and dictionary in python regarding the mutable is that lists are mutable, which means they can be changed. The tuple is immutable, which means it cannot be changed. The set is mutable, which means that we can change it. However, no elements are duplicated. The dictionary is mutable. However, keys are not duplicated.

• The difference between List, tuple, set and dictionary in python regarding the order is that the list is ordered. The tuple has been ordered. The set is unordered. The dictionary has been ordered (Python 3.7 and above).

• This is an essential Python Data Structure. A Python set differs from a list or a tuple in some ways. In Python, a set is the same as a mathematical set. It is unordered and does not contain duplicate values. However, unlike a tuple, it is not immutable.

### GATE & PSU CS

Computer ScienceGATEGATE CSENIELITOther ExamsQuick LinksMock Test