List, Tuple, Set and Dictionary: Lists List Is A Collection Which Is Ordered
List, Tuple, Set and Dictionary: Lists List Is A Collection Which Is Ordered
List and Tuple objects are sequences. A dictionary is a hash table of key-value pairs. List and tuple
is an ordered collection of items. Dictionary is unordered collection.
List and dictionary objects are mutable i.e. it is possible to add new item or delete and item from it.
Tuple is an immutable object. Addition or deletion operations are not possible on tuple object.
Each of them is a collection of comma-separated items. List items are enclosed in square brackets
[], tuple items in round brackets or parentheses (), and dictionary items in curly brackets {}
List and tuple items are indexed. Slice operator allows item of certain index to be accessed
Lists
List is a collection which is ordered.
Lists are mutable (changeable) .
Allows duplicate members
Brackets used to represent: []
Lists are like arrays declared in other languages.
Tuples
Collection of items which is ordered.
Tuples are immutable (unchangeable) .
Brackets used to represent: ()
Only difference between tuples and lists are that lists can be changed.
Tuples are faster than lists as they are immutable.
Sets
Collection of Unordered and Unindexed items.
Sets are mutable (changeable).
Does not take duplicate Values.
Sets are unordered, so you cannot be sure in which order the items will appear.
Brackets used to represent: { }.
Sets are not faster than lists however they have a upper hand when it comes to membership
testing.
Dictionaries
Key:Value Pair in Python
A dictionary is a collection which is unordered, changeable and indexed.
In Python dictionaries are written with curly brackets, and they have keys and values.
Brackets used to represent: {}.