# Python Dictionaries and Tuples.(Week 8)
This week, I continued my Python programming journey at Blockfuse Labs with a focus on Dictionaries and Tuples, two essential data structures that are widely used in software development for data storage and retrieval.
## Python Dictionaries
A dictionary in Python is a collection of key-value pairs, where each key is unique and is used to store and retrieve data efficiently. Unlike lists, which use indexes, dictionaries use keys to access values.
Features of a Dictionary.
Mutable (can be changed after creation)
Dictionaries are Unordered (Python 3.7+ maintains insertion order).
Keys must be unique and immutable (strings, numbers, tuples).
```
Example 1: Creating and Accessing a Dictionary
# Creating a dictionary of student scores
student_scores = {
"Alice": 85,
"Bob": 72,
"Charlie": 90
}
# Accessing value
print(student_scores["Alice"]) # Output: 85
# Adding a new entry
student_scores["David"] = 78
# Updating an existing entry
student_scores["Bob"] = 80
# Iterating through dictionary
for name, score in student_scores.items():
print(f"{name}: {score}")
Output:
85
Alice: 85
Bob: 80
Charlie: 90
David: 78
```
## Understanding Python Tuples
A tuple is similar to a list but it is immutable, meaning its contents cannot be modified after creation. Tuples are ideal for storing fixed data that should not change.
### Tuples Features:
```
Immutable (cannot add, remove, or change items).
Ordered collection.
Allows duplicate values.
Example 1: Creating and Using Tuples
# Creating a tuple of coordinates
coordinates = (12.4, 8.9)
# Accessing tuple elements
print(coordinates[0]) # Output: 12.4
# Tuple unpacking
x, y = coordinates
print(f"x: {x}, y: {y}")
Output:
12.4
x: 12.4, y: 8.9
```
This week's focus on dictionaries and tuples has strengthened my understanding of data organization and retrieval in Python, preparing me for more complex data structures and problem-solving techniques in future lessons.
Thank you as usual for stopping by to read my progress. See again soon.