Difference between the list ,sets,tuples, and dict

Submitted 4 years, 2 months ago
Ticket #338
Views 350
Language/Framework Python
Priority Low
Status Closed

I am unable to understand what is the difference between the sets,lists,tuples,and dict....

And when to use those ....

Any help will be greatly appreciated.....

Submitted on Feb 04, 21
add a comment

1 Answer

Verified

List Tuple Set Dictionary
List is a non-homogeneous data structure which stores the elements in single row and multiple rows and columns Tuple is also a non-homogeneous data structure which stores single row and multiple rows and columns Set data structure is also non-homogeneous data structure but stores in single row Dictionary is also a non-homogeneous data structure which stores key value pairs
List can be represented by [ ]

Tuple can be represented by  

( )

Set can be represented by { } Dictionary  can be represented by { }
List allows duplicate elements Tuple allows duplicate elements Set will not allow duplicate elements Set will not allow duplicate elements but keys are not duplicated
List can use nested among all Tuple can use nested among all Set can use nested among all Dictonary can use nested among all
Example: [1, 2, 3, 4, 5] Example: (1, 2, 3, 4, 5) Example: {1, 2, 3, 4, 5} Example: {1, 2, 3, 4, 5}
List can be created using list() function Tuple can be created using tuple() function. Set can be created using set() function Dictonary can be created using dict() function.
List is mutable i.e we can make any changes in list. Tuple  is immutable i.e we can not make any changes in tuple Set is mutable i.e we can make any changes in set. But elements are not duplicated. Dictionary is mutable. But Keys are not duplicated.
List is ordered Tuple is ordered Set is unordered Dictionary is ordered

 

Submitted 4 years, 2 months ago
sai


Latest Blogs