Skip to content

Commit a313ebf

Browse files
committedMar 17, 2025
Day 6 - Lists & Tuples
1 parent 743149d commit a313ebf

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed
 

Diff for: ‎Day 6 - Lists & Tuples/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Day 6: Lists & Tuples
2+
3+
## What You'll Learn:
4+
- List creation and indexing
5+
- Essential list methods (append, remove, sort)
6+
- Tuple creation and unpacking
7+
- Immutable vs mutable differences
8+
9+
## Files:
10+
1. `list_methods.py` - Common list operations and methods
11+
2. `tuple_unpacking.py` - Working with tuples
12+
3. `list_operations.py` - Slicing and list manipulations
13+
14+
## Exercises:
15+
1. Create a shopping cart program that:
16+
- Allows adding/removing items
17+
- Displays total items and unique items
18+
- Calculates total price (items with prices)
19+
20+
2. Build a student grade system using tuples that:
21+
- Stores student records as (name, math_score, science_score)
22+
- Unpacks tuples to calculate average scores
23+
- Finds top performer in each subject

Diff for: ‎Day 6 - Lists & Tuples/list_methods.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# List creation and basic methods
2+
fruits = ["apple", "banana"]
3+
print(f"Original list: {fruits}")
4+
5+
# Adding elements
6+
fruits.append("orange")
7+
fruits.insert(1, "mango")
8+
print(f"After additions: {fruits}")
9+
10+
# Removing elements
11+
fruits.remove("banana")
12+
popped = fruits.pop()
13+
print(f"After removals: {fruits}, Popped: {popped}")
14+
15+
# Sorting
16+
numbers = [3, 1, 4, 1, 5]
17+
numbers.sort(reverse=True)
18+
print(f"Sorted numbers: {numbers}")

Diff for: ‎Day 6 - Lists & Tuples/list_operation.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Slicing
2+
numbers = [0, 1, 2, 3, 4, 5]
3+
print("Middle elements:", numbers[2:4])
4+
print("Last two:", numbers[-2:])
5+
6+
# List comprehension
7+
squares = [x**2 for x in range(1, 6)]
8+
print(f"Squares: {squares}")
9+
10+
# Combining lists
11+
list1 = [1, 2, 3]
12+
list2 = [4, 5]
13+
combined = list1 + list2
14+
print(f"Combined: {combined}")

Diff for: ‎Day 6 - Lists & Tuples/tuple_unpacking.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Basic tuple
2+
dimensions = (1920, 1080)
3+
width, height = dimensions
4+
print(f"Resolution: {width}x{height}")
5+
6+
# Multiple return values
7+
def get_user_info():
8+
return "John", "Doe", 30
9+
10+
first, last, age = get_user_info()
11+
print(f"{first} {last}, {age} years old")
12+
13+
# Extended unpacking
14+
values = (1, 2, 3, 4, 5)
15+
a, b, *rest = values
16+
print(f"First: {a}, Second: {b}, Rest: {rest}")

0 commit comments

Comments
 (0)