When to use list vs. tuple vs. dictionary vs. set?

When to use list vs. tuple vs. dictionary vs. set?

List is like array, it can be used to store homogeneous as well as heterogeneous data type (It can store same data type as well as different data type). List are faster compared to array. Individual element of List data can be accessed using indexing & can be manipulated.

List Code Snippet:
list = ["Sarah",29,30000.00]
for i in range (3):
   print list[i]
------------------
Output
Sarah
29
30000.0

Tuples are similar to lists, but there data can be changed once created throught the execution of program. Individual element of Tuples can be accessed using indexing.

Tuples Code Snippet: The Days

days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
print days
------------------------------
('Sunday', 'Mondays', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')

Sets stores unordered values & have no index. And unlike Tuples and Lists, Sets can have no duplicate data, It is similar to Mathematical sets.- add() function can be used to add element to a set.
- update() function can be used to add a group of elements to a set.
- Copy() function can be used to create clone of set.

Set Code Snippet:
disneyLand = set (['Minnie Mouse', 'Donald Duck', 'Daisy Duck', 'Goofy'])
disneyLand.add('Pluto')
print disneyLand
-----------------------------------------------
Output
set(['Goofy', 'Daisy Duck', 'Donald Duck', 'Minnie Mouse', ’Pluto’])

Dictionary are similar to what their name is. In a dictionary, In python, the word is called a 'key', and the definition a 'value'. Dictionaries consist of pairs of keys and their corresponding values.

Dictionary Code Snippet:
>>> dict = {'India': 'Bharat', 'Angel': ‘Mother Teresa’, 'Cartoon': 'Mickey'}
>>>print dict[India]
Bharat
>>>print dict[Angel]
Mother Teresa
Disadvantages of python
Disadvantages of Python are: Python isn't the best for memory intensive tasks........
30 Siebel Interview Questions and Answers - Freshers, Experienced
Siebel interview questions and answers for freshers and experienced - Here are all possible Siebel interview questions with answers that might be asked during interview.
Determine OOTB functionality in Siebel
Determine OOTB functionality in Siebel - There are quite a few vanilla functionalities available within the product in Siebel.....
Post your comment
Discussion Board
When to use list vs tuple vs dictionary
Your article describes some differences in the components, defining each component explaining them to a basic extent with a short sample code. However; no where does your article ever answer the question when to use each one . For that matter it would also be nice to have not only the answer but a valid reason why ?
Stix 05-15-2015
type correction
I think there is a typo in the article, Tuples are immutable, "Tuples Cannot be changed once created"
Rajesh 01-13-2015
When to use list vs. tuple vs. dictionary vs. set?
"Tuples are similar to lists, but there data can be changed once created throught the execution of program. Individual element of Tuples can be accessed using indexing."

Official documentation has different point of view. According to it - "Tuples, like strings, are immutable"
https://docs.python.org/release/1.5.1p1/tut/tuples.html
Volodymyr 11-25-2014