---
# System prepended metadata

title: Weekly Report/ Week 9

---

# Weekly 9 Recap: Getting Hands-On With Collections (Iterables) Data Types in Python

This past week, I focused on Python’s collection data types — not just learning what they do, but actually messing around with them, making silly mistakes, and slowly getting what makes each one unique.

If you're new to Python, you’ll quickly meet these four:

* **Lists** → for ordered and changeable stuff
* **Tuples** → for ordered but unchangeable stuff
* **Sets** → for unordered, unique stuff
* **Dictionaries** → for key-value pairing (like real-life labels)

Let me break down how things actually felt while learning them, including the times I messed up.

Lists (My Go-To Storage Buddy)

Lists feel like a backpack. I can open it, add things, remove things, even rearrange what’s inside.

```python
items = ["pen", "book", "bottle"]
items.append("charger")
print(items)
```

Easy enough. But I once tried this:

```python
items.add("laptop")
```

And Python said:

```
AttributeError: 'list' object has no attribute 'add'
```

That was my first shocker. Turns out, `add()` is for **sets**, not lists. Lists use `append()`.

Another common method:

```python
items.insert(1, "pencil")  # Adds "pencil" at index 1
items.remove("book")       # Removes "book"
```

And I learned you can even slice a list:

```python
print(items[1:3])  # Gets items between index 1 and 2
```


###  Tuples, Locked After Creation

Tuples are like sealed boxes. Once you pack it, it’s done.

```python
stuff = ("water", "food", "map")
```

I naively tried to update one item:

```python
stuff[0] = "juice"
```

Python was like:

```
TypeError: 'tuple' object does not support item assignment
```

So yeah, tuples are **immutable**. I started using them when I wanted to lock data — things that shouldn’t accidentally change later in my code.



### Sets (Unordered Data Type in Python)

Sets confused me at first.

```python
colors = {"red", "blue", "green"}
```

Then I tried adding a duplicate:

```python
colors.add("blue")
print(colors)
```

Nothing changed. That’s when I got it: sets don’t allow duplicates.

Also, you can’t do this:

```python
print(colors[0])
```

Error:

```
TypeError: 'set' object is not subscriptable
```

Meaning, sets don’t support indexing. They're like chaotic bags of unique things.

Useful methods I liked:

```python
colors.remove("red")
colors.clear()  # Empties the set
```
![Screenshot 2025-08-04 at 8.42.18 AM](https://hackmd.io/_uploads/Hy2qN1RPxx.png)

---

### Dictionaries {key:value}

This one just clicked for me. Simply, dictionary is a key value pair in python

```python
person = {"name": "Ada", "age": 25, "city": "Lagos"}
```

I could grab values using keys:

```python
print(person["age"])
```

But I once tried:

```python
print(person[1])
```

Python said:

```
KeyError: 1
```

That was my reminder — dictionary keys aren’t like list indexes. They’re whatever you define them as.

Also loved this method:

```python
print(person.get("country", "Not available"))
```

It lets me avoid errors when the key isn’t there.
![Screenshot 2025-08-04 at 8.42.26 AM](https://hackmd.io/_uploads/HkPCEJAveg.png)



### Little Mistakes That Taught Me Big Lessons

* Mixing up `add()` and `append()` happens a lot.
* Forgetting that tuples can’t be changed messed me up in one exercise.
* I once wrote `{}` thinking I had an empty set, but that actually creates an empty dictionary.
  To create an empty set, you must do:

  ```python
  my_set = set()
  ```

What I’m Taking Forward

This week wasn’t about writing the most perfect code — it was more about seeing how these tools work in real life. I now know which data type to use depending on the situation:

* Need order + flexibility? Use a list.
* Need to lock data? Tuple.
* Need uniqueness? Set.
* Need to label and pair values? Dictionary.




