-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_collections.py
More file actions
57 lines (42 loc) · 1.52 KB
/
05_collections.py
File metadata and controls
57 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Examples of Python collection types:
- lists (ordered, mutable)
- tuples (ordered, immutable)
- dictionaries (key-value mappings)
This module demonstrates basic creation, iteration, and updates.
"""
from typing import List, Dict, Tuple
def list_habits() -> List[str]:
"""Return a simple list of daily habits."""
return ["Workout", "Code", "Read", "Meditate"]
def tuple_schedule() -> Tuple[str, str, str]:
"""Return an example tuple representing a fixed morning schedule."""
return ("Wake up", "Cold plunge", "Coffee + focus work")
def habit_completion_status() -> Dict[str, bool]:
"""Return a dictionary mapping habits to completion status."""
return {
"Workout": True,
"Code": False,
"Read": True,
"Meditate": False,
}
def print_collection(title: str, items) -> None:
"""Pretty-print list, tuple, or dictionary content."""
print(f"\n{title}:")
if isinstance(items, dict):
for key, value in items.items():
status = "✔️ Done" if value else "❌ Not done"
print(f"- {key}: {status}")
else:
# Works for both lists and tuples
for index, item in enumerate(items, start=1):
print(f"{index}. {item}")
def main() -> None:
habits = list_habits()
schedule = tuple_schedule()
status = habit_completion_status()
print_collection("Daily Habits", habits)
print_collection("Morning Schedule", schedule)
print_collection("Habit Completion Status", status)
if __name__ == "__main__":
main()