Jan 26, 2026
# Chapter 6 — Lists, Tuples, Sets, and Dicts (The Daily Tools)
This chapter is written like a cheat-sheet + mini exercises.
## 6.1 List
```python
scores = [10, 20, 30]
scores.append(40)
print(scores[0])
```
## 6.2 Tuple (Fixed Collection)
```python
point = (3, 4)
print(point[1])
```
## 6.3 Set (Unique Items)
```python
names = {"a", "b", "a"}
print(names)
```
## 6.4 Dict (Key → Value)
```python
user = {"name": "Riya", "site": "meetcode"}
print(user["name"])
user["role"] = "student"
print(user)
```
### Diagram: Dict as a Map
```text
name -> "Riya"
site -> "meetcode"
role -> "student"
```
## 6.5 Lists Are Mutable (Most Important List Fact)
Mutable means: you can change the same list object.
```python
a = [1, 2, 3]
b = a
a.append(4)
print(a, b)
```
Both show the change, because both names point to the same list.
### Diagram: Two Labels, One List
```text
a ----
---> [1, 2, 3, 4]
b ----/
```
## 6.6 Copying Lists (Shallow Copy, Common Trap)
If you want a new list object:
```python
a = [1, 2, 3]
b = list(a)
a.append(4)
print(a, b)
```
But if a list contains other lists, you must be careful:
```python
grid = [[1, 2], [3, 4]]
copy1 = list(grid)
grid[0].append(99)
print(grid, copy1)
```
The inner lists are still shared. That is why people call it a “shallow” copy.
## 6.7 Slicing (Readable and Powerful)
```python
nums = [10, 20, 30, 40, 50]
print(nums[1:4])
print(nums[:3])
print(nums[::2])
```
## 6.8 List Comprehension (Clean Loops)
```python
nums = [1, 2, 3, 4, 5]
squares = [n * n for n in nums]
evens = [n for n in nums if n % 2 == 0]
print(squares, evens)
```
## 6.9 Sorting (Stable, Key-Based, Real-World)
```python
students = [
{"name": "Asha", "score": 90},
{"name": "Ravi", "score": 75},
{"name": "Meera", "score": 90},
]
sorted_students = sorted(students, key=lambda s: (-(s["score"]), s["name"]))
print(sorted_students)
```
Sorting becomes easy when you think: “What key should decide the order?”
## 6.10 Dict Patterns You Use Daily
### Safe read with default
```python
user = {"name": "Asha"}
print(user.get("role", "student"))
```
### Counting with a dict (classic interview + real work)
```python
text = "meetcode"
count = {}
for ch in text:
count[ch] = count.get(ch, 0) + 1
print(count)
```
---
## Conclusion
In this article, we explored the core concepts of All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools). Understanding these fundamentals is crucial for any developer looking to master this topic.
## Frequently Asked Questions (FAQs)
**Q: What is All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools)?**
A: All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools) is a fundamental concept in this programming language/topic that allows developers to perform specific tasks efficiently.
**Q: Why is All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools) important?**
A: It helps in organizing code, improving performance, and implementing complex logic in a structured way.
**Q: How to get started with All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools)?**
A: You can start by practicing the basic syntax and examples provided in this tutorial.
**Q: Are there any prerequisites for All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools)?**
A: Basic knowledge of programming logic and syntax is recommended.
**Q: Can All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools) be used in real-world projects?**
A: Yes, it is widely used in enterprise-level applications and software development.
**Q: Where can I find more examples of All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools)?**
A: You can check our blog section for more advanced tutorials and use cases.
**Q: Is All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools) suitable for beginners?**
A: Yes, our guide is designed to be beginner-friendly with clear explanations.
**Q: How does All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools) improve code quality?**
A: By providing a standardized way to handle logic, it makes code more readable and maintainable.
**Q: What are common mistakes when using All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools)?**
A: Common mistakes include incorrect syntax usage and not following best practices, which we've covered here.
**Q: Does this tutorial cover advanced All about Python - — Lists, Tuples, Sets, and Dicts (The Daily Tools)?**
A: This article covers the essentials; stay tuned for our advanced series on this topic.