🌐
Purdue University
purdue.edu › hla › sites › varalalab › wp-content › uploads › sites › 20 › 2018 › 03 › Lecture_10.pdf pdf
Lists, Tuples and Dictionaries HORT 59000 Lecture 10 Instructor: Kranthi Varala
• Dictionaries · • Tuples · • Files · • Sets · References and dynamic typing · • Dynamic typing allows changing the type of a variable. • A = ‘42’ now changes the apparent data type of A to an · integer. • The reference from A to ‘Sample String’ is removed. • B still points to the ‘Sample String’ object. • If all variable reference are removed from an object, the · object will be marked for removal by Python...
🌐
Scribd
scribd.com › document › 875892732 › Practice-Questions-for-List-Tuple-Set-and-Dictionary-and-Functions
Python Practice: Lists, Tuples, Sets, Dicts | PDF | Parameter (Computer Programming) | Function (Mathematics)
Practice Questions for List Tuple Set and Dictionary and Functions - Free download as Word Doc (.doc / .docx), PDF File (.pdf), Text File (.txt) or read online for free. The document provides a series of practice questions and answers related to Python data structures including lists, tuples, sets, and dictionaries.
Discussions

Beginner to python: Lists, Tuples, Dictionaries, Sets - Stack Overflow
I have been trying to understand what the difference is between lists, tuples, dictionaries, and sets. All I've been able to gather is they use different brackets or braces. () {} []. Some are able... More on stackoverflow.com
🌐 stackoverflow.com
When should I use a list, dictionary, tuple, or set in Python?
IMO: and this is controversial but will greatly help you organize your data, don't lump tuples in with lists, dictionaries, and sets. A tuple isn't a collection, it's a type. That is, use a tuple when your single object has multiple properties. Like a name or a coordinate. A first and last name together form a name, they don't have much value separately, and the constitute the entirely of the object. In this sense, a tuple of first_name, last_name is a single object, not a collection of separate strings. For example, a CSV file is "best" represented as a list of tuples. Each line is a single thing, but with multiple properties all of which are related. Column 1 and column 2 of a row aren't really a sequence or or collection, but rather feathers on the same chicken (tuple). However, Row 1 and row 2 are related only in that they are the same kind of thing stored together (list). We put the tuples in the list because the parts of the row are more related than the rows of the document. Think about type-hinting a tuple vs a list: a list hint takes exactly one type, and the expectation is that there will be several objects of that type. Conversely, a tuple hint easily accepts multiple types, but needs to know the exact number and position of each type. It's not so much that a tuple is an immutable container, but that a tuple stores an immutable thing. List: Use it when you need to store a lot of the same thing. It's ordered, but it doesn't need to be limited to ordered sequences. That is, a list is generally okay as long as the items don't need to be unordered. A list is good at iterating, but bad at selection, so use it when you will be looping over the items, but not selecting at random. Tuple: A tuple is one thing. You generally don't use it for storage, but for structure. When you have a thing with multiple parts, that's a tuple. When you have multiple things, that's a list. Unlike a list, a tuple is very likely to contain different types, while a list is (should) contain elements of a single type. Again, a tuple is good at iteration and bad at selection. A dictionary and set are really close to the same thing--they are hashes. Hashes are bad at iteration, but good at selection, so they are best when you need to select items from the container at random--not in order. They are semi-ordered, meaning you can now expect the order to remain, but if you need items to be in order it's probably not the right type. If you need a key->value relationship, then you want a dict, otherwise, you want a set. Use lists when order matters and you need to modify elements. Order doesn't need to matter, it just needs to be inconsequential. Also, avoid the "modify" criteria as almost all "real" collections are modifiable. Lists end up being sort of a "default", so without a reason to choose something else, or a reason to avoid a list, most of the time a list is fine. Use tuples when you need an immutable sequence (e.g., function return values). Again, look at this as a single object. Use tuples when you are returning a complex single object, not a sequence. You can return a list from a function just as easily as a tuple, so I don't consider return values a good selection criteria. However, your function should be returning "one thing", so in that sense a tuple makes sense, but from the other direction. Use sets when you need fast lookups and uniqueness. Use dictionaries when mapping keys to values efficiently. again, I would avoid thinking about sets and dictionaries as a top-level division. Instead, think "do I need a hash", and then "do I need key->value pairs" to choose between them. Is this not actually a collection of separate, but similar, objects? Then you want a tuple, or something more sophisticated like a NamedTuple, DataClass, or Class Is this a sequence? That is, do you need these items in order, or don't care about which one you get next, or will be dealing with all the items at once (even if one-by-one)? This is a list. Is this more of a "soup"? Where you want a specific item next, and don't care about order, or will be dealing with only specific objects at once? More on reddit.com
🌐 r/learnpython
24
100
March 6, 2025
Why doesn't dict.items() and dict.keys() return a list?

What is the benefit of these objects?

A list has to load all its data into memory before doing anything. These objects just reference the underlying dict, not duplicating anything. This means that they are less memory-hungry and that, if you are apt to exit the loop quickly, you didn't pay to copy everything beforehand.

To me they just seem to introduce unnecessary complexity to my code.

It is one more thing to keep in mind, and I share your skepticism about its value. Ultimately, few will share it.

FWIW, numpy.array does more guessing than your average nice function, and this leads to a lot of stuff like this. I'm not sure that there is a nice API it could provide that didn't have such hiccups sometimes, though.

More on reddit.com
🌐 r/Python
83
76
March 29, 2016
Real-world example of using lists/tuples/dictionaries?
Lists: You can use these when you need a collection of similar/non similar items. Suppose you are making a program that randomly picks a name from a hat. You could do something like this: from random import choice names = ["Bob", "Jim", "Rodger", "Dave"] print(choice(names) >> Jim Tuples are generally used for smaller groups of similar items, things like coordinate systems. Kwargs are passed as a tuple when a function is called. Dictionaries are used when you need a lot of organization because the data is very dependent on each other. Suppose needed to know if a group of people voted yet today (Election day) You dould do: voters = { "Jim" = False "Bob" = True "Dave" = True } More on reddit.com
🌐 r/learnpython
18
14
November 5, 2013
People also ask

Explain the process and benefit of using list methods like 'insert', 'remove', and 'sort' in Python list manipulation.
The 'insert()' method allows for inserting elements at specified positions, effectively growing the list while placing data precisely where needed, demonstrated by 'num.insert(2,77)' . The 'remove()' function facilitates the deletion of specified values, helping to maintain list integrity by eliminating unwanted elements safely, as in 'num.remove(14)' . The 'sort()' method organizes list data in ascending order, enabling streamlined data processing and comparison, such as transforming '[25, 77, 29, 12, 14, 36]' into '[12, 14, 25, 29, 36, 77]' .
🌐
scribd.com
scribd.com › document › 623875983 › 31-01-23-LIST-TUPLE-SETS-AND-DICTIONARY-IN-PYTHON
31 01 23 LIST, TUPLE, SETS AND DICTIONARY IN PYTHON
How can nested dictionaries in Python be used to represent complex data structures, and what is one example of accessing nested values?
Nested dictionaries in Python can represent complex data structures by storing dictionaries within dictionaries. This allows for hierarchical data storage and efficient organization. An example of accessing nested values is 'prog['JAVA']['JEE']', which retrieves 'ECLIPSE' from a nested dictionary structure {'JAVA': {'JSE': 'NETBEANS', 'JEE': 'ECLIPSE'}} .
🌐
scribd.com
scribd.com › document › 623875983 › 31-01-23-LIST-TUPLE-SETS-AND-DICTIONARY-IN-PYTHON
31 01 23 LIST, TUPLE, SETS AND DICTIONARY IN PYTHON
Why is the 'pop()' method in Python significant for managing list data, and how can it be used differently?
The 'pop()' method is significant in Python as it allows the removal and retrieval of elements at specified positions, ensuring data integrity and facilitating dynamic list management. It can remove the last item by default, as 'num.pop()' shows by removing '45', or specific elements, such as 'num.pop(1)' which removes '12' and 'num.pop(3)' which targets '95', providing agility in how data is managed .
🌐
scribd.com
scribd.com › document › 623875983 › 31-01-23-LIST-TUPLE-SETS-AND-DICTIONARY-IN-PYTHON
31 01 23 LIST, TUPLE, SETS AND DICTIONARY IN PYTHON
🌐
Scribd
scribd.com › document › 677662436 › 6-List-Tuple-Set-Dictionary-1
List, Tuple, Set, Dictionary | PDF | Computer Science | Software Development
The document discusses lists, tuples, sets, and dictionaries in Python. It provides: 1) An introduction to each data type, explaining their properties like mutability and ordering; ...
🌐
Slideshare
slideshare.net › home › engineering › list,tuple,dictionary
List,tuple,dictionary | PDF
May 14, 2025 - The document discusses Python's four main collection data types: lists, tuples, sets, and dictionaries. It provides details on lists, including that they are ordered and changeable collections that allow duplicate members.
🌐
Amgrubb
amgrubb.github.io › csc111 › notes › W6.pdf pdf
Topic 6: Lists, Sets, Tuples, Dictionaries
Topic 6: Lists, Sets, Tuples, Dictionaries · Goals: By the end of this week, we will discuss…
🌐
PA Engineering College
pace.edu.in › img › course › COURSE MATERIAL_2ND_YEAR_18BT36_MODULE_4.pdf pdf
UNIT IV COMPOUND DATA: LISTS, TUPLES, DICTIONARIES
Python provides methods that operate on lists. ... A loop becomes infinite loop if the condition given never becomes false. It keeps on ...  Creating a copy of a same list of elements with two different memory locations is called cloning. ...  Passing a list as an argument actually passes a reference to the list, not a copy of the list. ... Delete the entire tuple...
🌐
GeeksforGeeks
geeksforgeeks.org › python › differences-and-applications-of-list-tuple-set-and-dictionary-in-python
Differences and Applications of List, Tuple, Set and Dictionary in Python - GeeksforGeeks
October 3, 2025 - Tuples are ideal for grouping data of different types like user records. ... A Python set is an unordered collection of unique elements. It is mutable, meaning you can add or remove elements (only regular sets), and it supports mathematical operations like union, intersection, and difference. ... Regular sets (set) are mutable and therefore not hashable. They cannot be used as dictionary keys or stored inside other sets.
Find elsewhere
🌐
Scribd
scribd.com › document › 623875983 › 31-01-23-LIST-TUPLE-SETS-AND-DICTIONARY-IN-PYTHON
31 01 23 LIST, TUPLE, SETS AND DICTIONARY IN PYTHON
January 31, 2023 - 31 01 23 LIST, TUPLE, SETS AND DICTIONARY IN PYTHON - Free download as Text File (.txt), PDF File (.pdf) or read online for free. The document discusses various data structures in Python - lists, tuples, sets, and dictionaries. It provides examples of creating, accessing, modifying, and iterating ...
🌐
Stanford University
web.stanford.edu › ~schmit › cme193 › lec › lec3.pdf pdf
CME 193: Introduction to Scientific Python
We can turn anything in Python into a string using str. This includes dictionaries, lists, tuples, etc.
Top answer
1 of 2
1

List and tuple are similar to dynamic arrays where in list are mutable but tuples are not. You could checkout the documentation for list and tuple https://docs.python.org/3.8/library/stdtypes.html#sequence-types-list-tuple-range

A set is an unordered collection of objects. Link to the docs: https://docs.python.org/3.8/library/stdtypes.html#set-types-set-frozenset

A dict maps hashable values to arbitrary objects. Mappings are mutable objects. Link to the docs: https://docs.python.org/3.8/library/stdtypes.html#mapping-types-dict

2 of 2
0
  1. List : Used to store the items. Duplicates can also be stored. Order of storing will be maintained as is. It is mutable which means the same object can be altered after creation. Example :

    list1 = ['one',2,3.4,'hello']
    print(list1)
    print(list1[3])
    list1[1]=2 #allowed
    print(list1)
    

    Answer:

        'one', 2, 3.4, 'hello']
        hello
        [2, 2, 3.4, 'hello']
    
  2. Set : Just like list. Only difference is it cannot store the duplicate values. Also there will be no order in which values are stored.

Example:

>>>#set of integers
>>>s = {1, 2, 3}
>>>print(s)
{1, 2, 3}
>>>#print type of s 
>>>print(type(s))
<class 'set'>
>>> x = set(['foo', 'bar', 'baz', 'foo', 'qux'])
>>> x
{'qux', 'foo', 'bar', 'baz'}
  1. Dictionary : Dictionary is basically a storage type in which you can store a value corresponding to a key just like a real life dictionary.

Example:

>>>dictval = {"Nishant":1,"Akash":2,"Ravi":3,"Hari":4}
>>>print(dictval)
{'Nishant': 1, 'Akash': 2, 'Ravi': 3, 'Hari': 4}
>>>print(dictval["Akash"])
2
  1. Tuple: A tuple is a sequence of values much like a list. The values stored in a tuple can be any type, and they are indexed by integers. The important difference is that tuples are immutable.That we can’t change the elements of tuple once it is assigned whereas in the list, elements can be changed.

Example:

>>>#tuple with mixed datatypes
>>>t = (1, 'raju', 28, 'abc')
>>>print(t)
>>>print(t[1])
(1, 'raju', 28, 'abc')
raju

>>>t = (1, 'raju', 28, 'abc')
>>>print(t)
>>>print(t[3])
>>>t[3] = 'def'
(1, 'raju', 28, 'abc')
abc
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-254e32ad7a3c> in <module>()
      2 print(t)
      3 print(t[3])
----> 4 t[3] = 'def'
TypeError: 'tuple' object does not support item assignment
🌐
Reddit
reddit.com › r/learnpython › when should i use a list, dictionary, tuple, or set in python?
r/learnpython on Reddit: When should I use a list, dictionary, tuple, or set in Python?
March 6, 2025 -

Hey everyone,

I’m trying to get a deeper understanding of Python’s built-in data structures—specifically lists, dictionaries, tuples, and sets. I understand their basic properties:

Lists (list) → Ordered, mutable, allows duplicates

Tuples (tuple) → Ordered, immutable, allows duplicates

Dictionaries (dict) → Key-value pairs, unordered (but ordered since Python 3.7), keys must be unique

Sets (set) → Unordered, mutable, unique elements only

But I'm struggling to figure out when to use each of them in real-world scenarios. I know some general guidelines, like:

Use lists when order matters and you need to modify elements.

Use tuples when you need an immutable sequence (e.g., function return values).

Use sets when you need fast lookups and uniqueness.

Use dictionaries when mapping keys to values efficiently.

However, I’d love to hear from experienced Python developers:

Are there any specific patterns or real-world examples where one of these structures is clearly the best choice?

Have you ever misused one and later realized another structure would have been better?

Are there any performance considerations that I should be aware of when choosing between them?

Looking forward to your insights! Thanks in advance.

Top answer
1 of 15
69
IMO: and this is controversial but will greatly help you organize your data, don't lump tuples in with lists, dictionaries, and sets. A tuple isn't a collection, it's a type. That is, use a tuple when your single object has multiple properties. Like a name or a coordinate. A first and last name together form a name, they don't have much value separately, and the constitute the entirely of the object. In this sense, a tuple of first_name, last_name is a single object, not a collection of separate strings. For example, a CSV file is "best" represented as a list of tuples. Each line is a single thing, but with multiple properties all of which are related. Column 1 and column 2 of a row aren't really a sequence or or collection, but rather feathers on the same chicken (tuple). However, Row 1 and row 2 are related only in that they are the same kind of thing stored together (list). We put the tuples in the list because the parts of the row are more related than the rows of the document. Think about type-hinting a tuple vs a list: a list hint takes exactly one type, and the expectation is that there will be several objects of that type. Conversely, a tuple hint easily accepts multiple types, but needs to know the exact number and position of each type. It's not so much that a tuple is an immutable container, but that a tuple stores an immutable thing. List: Use it when you need to store a lot of the same thing. It's ordered, but it doesn't need to be limited to ordered sequences. That is, a list is generally okay as long as the items don't need to be unordered. A list is good at iterating, but bad at selection, so use it when you will be looping over the items, but not selecting at random. Tuple: A tuple is one thing. You generally don't use it for storage, but for structure. When you have a thing with multiple parts, that's a tuple. When you have multiple things, that's a list. Unlike a list, a tuple is very likely to contain different types, while a list is (should) contain elements of a single type. Again, a tuple is good at iteration and bad at selection. A dictionary and set are really close to the same thing--they are hashes. Hashes are bad at iteration, but good at selection, so they are best when you need to select items from the container at random--not in order. They are semi-ordered, meaning you can now expect the order to remain, but if you need items to be in order it's probably not the right type. If you need a key->value relationship, then you want a dict, otherwise, you want a set. Use lists when order matters and you need to modify elements. Order doesn't need to matter, it just needs to be inconsequential. Also, avoid the "modify" criteria as almost all "real" collections are modifiable. Lists end up being sort of a "default", so without a reason to choose something else, or a reason to avoid a list, most of the time a list is fine. Use tuples when you need an immutable sequence (e.g., function return values). Again, look at this as a single object. Use tuples when you are returning a complex single object, not a sequence. You can return a list from a function just as easily as a tuple, so I don't consider return values a good selection criteria. However, your function should be returning "one thing", so in that sense a tuple makes sense, but from the other direction. Use sets when you need fast lookups and uniqueness. Use dictionaries when mapping keys to values efficiently. again, I would avoid thinking about sets and dictionaries as a top-level division. Instead, think "do I need a hash", and then "do I need key->value pairs" to choose between them. Is this not actually a collection of separate, but similar, objects? Then you want a tuple, or something more sophisticated like a NamedTuple, DataClass, or Class Is this a sequence? That is, do you need these items in order, or don't care about which one you get next, or will be dealing with all the items at once (even if one-by-one)? This is a list. Is this more of a "soup"? Where you want a specific item next, and don't care about order, or will be dealing with only specific objects at once?
2 of 15
27
Tuple example below: I work with a lot of spatial information (latitudes, longitudes, etc.) whenever I’m processing this information I always make sure it is stored as a tuple because I don’t want to ever accidentally mess with that information since it’s tied to a specific place that someone cares about. Being off by X amount could be a big deal.
🌐
Medium
medium.com › @menkashah060 › mastering-python-collection-list-tuple-dictionary-and-set-explained-with-examples-16c0965c8506
📚Mastering Python Collection: List, Tuple, Dictionary, and Set Explained with Examples | by Menkashah | Medium
April 8, 2025 - Want to go deeper into these Python concepts with: ✅ Visual memory diagrams ✅ Hindi explanations for better understanding ✅ Real-world analogies & use-cases ✅ Beginner-friendly coding examples ... Mutability vs. Immutability (with memory reference diagrams 🧠💡) Lists, Tuples, Dictionaries, and Sets in detail (with illustrations) ... 🗣️ Comment “Yes” or DM me and I’ll share the full Hindi + Visual PDF ...
🌐
Anu-rses-education
anu-rses-education.github.io › EMSC-4033 › Notebooks › StepByStep › Ex05 › Ex5-ListsEtc.html
Exercise 5 - Lists, tuples and dictionaries — EMSC 4033 Computational Geoscience
For example, if we have an experimental dataset that consists of observations of pressure and temperature at a sequence of time points, it might be appropriate to represent each observation as a tuple of (pressure, temperature), and then the sequence of observations as a list of these tuples [(p1, T1), (p2, T2), (p3, T3),...]. Dictionaries provide a mechanism for storing data labelled with a keyword or other information.
🌐
SlideShare
slideshare.net › slideshow › list-tuples-dictionaries-and-regular-expressions-in-python › 234490728
List , tuples, dictionaries and regular expressions in python
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Scribd
scribd.com › document › 639334237 › List-Tuple-Set-and-Dictionary
List, Tuple, Set and Dictionary | PDF | Computer Science
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Tudelft
interactivetextbooks.tudelft.nl › python-handbook-for-engineering-students › content › book › basics › tuples-sets-dictionaries.html
4. Tuples, Sets, Dictionaries — Template Jupyter Book
.pdf · There are in total four built-in collection data types in Python: Lists are ordered, changeable and allow duplicate values. Tuples are ordered, unchangeable and allow duplicate values. Sets are unordered, unchangeable, unindexed and allow no duplicate values.
🌐
Medium
medium.com › @sankhasubhra.das.uemk.cse.2023 › list-tuple-set-dictionary-in-python-53056d2a1ad0
List, Tuple, Set & Dictionary in Python | by Sankha Subhra | Medium
September 1, 2023 - Tuple: Maintains order of elements. Set: No guaranteed order. Dictionary: Insertion order is preserved in Python 3.7+.