Skip to the content.

3.2 Hacks

Python Hacks

Hack #1

f1_data = {
    "Drivers": ["Lewis Hamilton", "Max Verstappen", "Charles Leclerc", "Fernando Alonso", "Lando Norris"],
    "Teams": ["Mercedes-AMG Petronas", "Red Bull Racing", "Ferrari", "McLaren", "Aston Martin"],
    "Circuits": ["Silverstone", "Monza", "Spa-Francorchamps", "Yas Marina", "Monaco"],
    "Grand Prix": ["British GP", "Italian GP", "Belgian GP", "Abu Dhabi GP", "Monaco GP"],
    "Records": ["Most Wins: Lewis Hamilton", "Most Championships: Michael Schumacher & Lewis Hamilton", "Youngest Race Winner: Max Verstappen"]
}

def print_f1_data(f1):
    for category, items in f1.items():
        print(f"\n{category}:")
        for item in items:
            print(f" - {item}")

print_f1_data(f1_data)

Drivers:
 - Lewis Hamilton
 - Max Verstappen
 - Charles Leclerc
 - Fernando Alonso
 - Lando Norris

Teams:
 - Mercedes-AMG Petronas
 - Red Bull Racing
 - Ferrari
 - McLaren
 - Aston Martin

Circuits:
 - Silverstone
 - Monza
 - Spa-Francorchamps
 - Yas Marina
 - Monaco

Grand Prix:
 - British GP
 - Italian GP
 - Belgian GP
 - Abu Dhabi GP
 - Monaco GP

Records:
 - Most Wins: Lewis Hamilton
 - Most Championships: Michael Schumacher & Lewis Hamilton
 - Youngest Race Winner: Max Verstappen

Hack #3

movie_rentals = [
    {
        "title": "Inception",
        "director": "Christopher Nolan",
        "genre": "Sci-Fi",
        "copies_available": 3,
        "renters": [
            {"name": "John Smith", "rent_date": "2024-10-01"},
            {"name": "Alice Johnson", "rent_date": "2024-10-03"}
        ]
    },
    {
        "title": "The Godfather",
        "director": "Francis Ford Coppola",
        "genre": "Crime",
        "copies_available": 1,
        "renters": [
            {"name": "Emily Davis", "rent_date": "2024-09-28"}
        ]
    },
    {
        "title": "The Lord of the Rings: The Return of the King",
        "director": "Peter Jackson",
        "genre": "Fantasy",
        "copies_available": 0,
        "renters": [
            {"name": "Michael Brown", "rent_date": "2024-09-25"},
            {"name": "Laura Wilson", "rent_date": "2024-09-30"}
        ]
    }
]

for movie in movie_rentals:
    print(f"Title: {movie['title']}")
    print(f"Director: {movie['director']}")
    print(f"Genre: {movie['genre']}")
    print(f"Copies Available: {movie['copies_available']}")
    print("Renters:")
    for renter in movie['renters']:
        print(f" - {renter['name']} (Rented on: {renter['rent_date']})")
    print("\n")

Title: Inception
Director: Christopher Nolan
Genre: Sci-Fi
Copies Available: 3
Renters:
 - John Smith (Rented on: 2024-10-01)
 - Alice Johnson (Rented on: 2024-10-03)


Title: The Godfather
Director: Francis Ford Coppola
Genre: Crime
Copies Available: 1
Renters:
 - Emily Davis (Rented on: 2024-09-28)


Title: The Lord of the Rings: The Return of the King
Director: Peter Jackson
Genre: Fantasy
Copies Available: 0
Renters:
 - Michael Brown (Rented on: 2024-09-25)
 - Laura Wilson (Rented on: 2024-09-30)

Hack #2

sprints = {
    'Sprint1': ['Frontend Development', 'Github Pages Playground', 'Javascript Playground', 'SASS Basics'],
    'Sprint2': ['Big Ideas 3.6', 'Big Ideas 3.7']
}

print(sprints['Sprint1'])
if "Frontend Development" in sprints['Sprint1']:
    print(True) 
else:
    print(False)
print()

HW Hack

movie_rentals = [
    {
        "title": "Inception",
        "director": "Christopher Nolan",
        "genre": "Sci-Fi",
        "copies_available": 3,
        "renters": [
            {"name": "John Smith", "rent_date": "2024-10-01"},
            {"name": "Alice Johnson", "rent_date": "2024-10-03"}
        ]
    },
    {
        "title": "The Godfather",
        "director": "Francis Ford Coppola",
        "genre": "Crime",
        "copies_available": 1,
        "renters": [
            {"name": "Emily Davis", "rent_date": "2024-09-28"}
        ]
    },
    {
        "title": "The Lord of the Rings: The Return of the King",
        "director": "Peter Jackson",
        "genre": "Fantasy",
        "copies_available": 0,
        "renters": [
            {"name": "Michael Brown", "rent_date": "2024-09-25"},
            {"name": "Laura Wilson", "rent_date": "2024-09-30"}
        ]
    }
]

for movie in movie_rentals:
    print(f"Title: {movie['title']}")
    print(f"Director: {movie['director']}")
    print(f"Genre: {movie['genre']}")
    print(f"Copies Available: {movie['copies_available']}")
    print("Renters:")
    for renter in movie['renters']:
        print(f" - {renter['name']} (Rented on: {renter['rent_date']})")
    print("\n")
Title: Inception
Director: Christopher Nolan
Genre: Sci-Fi
Copies Available: 3
Renters:
 - John Smith (Rented on: 2024-10-01)
 - Alice Johnson (Rented on: 2024-10-03)


Title: The Godfather
Director: Francis Ford Coppola
Genre: Crime
Copies Available: 1
Renters:
 - Emily Davis (Rented on: 2024-09-28)


Title: The Lord of the Rings: The Return of the King
Director: Peter Jackson
Genre: Fantasy
Copies Available: 0
Renters:
 - Michael Brown (Rented on: 2024-09-25)
 - Laura Wilson (Rented on: 2024-09-30)