100% found this document useful (1 vote)
1K views1 page

List, Tuple, Set and Dictionary

The document compares and contrasts four Python data structures: List, Tuple, Set, and Dictionary. It states that all four are non-homogeneous and can store elements in single or multiple rows/columns. Lists allow duplicates and are ordered/mutable. Tuples are immutable but ordered. Sets do not allow duplicates and are unordered. Dictionaries use keys and values, do not allow duplicate keys, and are ordered as of Python 3.7. Examples are provided for each data structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views1 page

List, Tuple, Set and Dictionary

The document compares and contrasts four Python data structures: List, Tuple, Set, and Dictionary. It states that all four are non-homogeneous and can store elements in single or multiple rows/columns. Lists allow duplicates and are ordered/mutable. Tuples are immutable but ordered. Sets do not allow duplicates and are unordered. Dictionaries use keys and values, do not allow duplicate keys, and are ordered as of Python 3.7. Examples are provided for each data structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

List Tuple Set Dictionary

List is a non- Tuple is also a non- Set data structure is Dictionary is also a non-
homogeneous homogeneous data also non- homogeneous data
data structure that structure that stores homogeneous data structure which stores key
stores the single row and structure but stores value pairs
elements in single multiple rows and in single row
row and multiple columns
rows and columns

List can be Tuple can be Set can be Dictionary can be


represented by represented by represented by represented by { }
[] {}
()

List allows Tuple allows Set will not allow Dictionary doesn’t allow
duplicate duplicate elements duplicate elements duplicate keys.
elements

List can use Tuple can use Set can use nested Dictionary can use nested
nested among all nested among all among all among all

Example: Example: Example: Example:


[1, 2, 3, 4, 5] (1, 2, 3, 4, 5) {1, 2, 3, 4, 5} {1: “a”, 2: “b”, 3: “c”, 4: “d”,
5: “e”}

List can be Tuple can be Set can be created Dictionary can be created
created created using set() using dict() function.
using list() using tuple() function
function function.

List is mutable i.e Tuple is immutable Set is mutable i.e we Dictionary is mutable. But
we can make any i.e we can not make can make any Keys are not duplicated.
changes in list. any changes in tuple changes in set. But
elements are not
duplicated.

List is ordered Tuple is ordered Set is unordered Dictionary is ordered


(Python 3.7 and above)

Creating an empty Creating an empty Creating a set Creating an empty


list Tuple dictionary
a=set()
l=[] t=() d={}
b=set(a)

You might also like