Skip to the content.

3.2 Hacks

hacks

Popcorn Hack 1

# Define a dictionary with books categorized by genre
book_genres = {
    "Fiction": ["The Great Gatsby", "1984", "To Kill a Mockingbird"],
    "Science Fiction": ["Dune", "Neuromancer", "Foundation"],
    "Fantasy": ["Harry Potter and the Sorcerer's Stone", "The Hobbit", "Mistborn: The Final Empire"],
    "Non-Fiction": ["Sapiens: A Brief History of Humankind", "Educated", "Becoming"]
}

# Function to print the list of books by genre
def print_books(genres):
    for genre, titles in genres.items():
        print(f"\n{genre}:")
        for title in titles:
            print(f" - {title}")

# Call the function to display books
print_books(book_genres)


Fiction:
 - The Great Gatsby
 - 1984
 - To Kill a Mockingbird

Science Fiction:
 - Dune
 - Neuromancer
 - Foundation

Fantasy:
 - Harry Potter and the Sorcerer's Stone
 - The Hobbit
 - Mistborn: The Final Empire

Non-Fiction:
 - Sapiens: A Brief History of Humankind
 - Educated
 - Becoming

Popcorn 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(sprints['Sprint2'])
if "Big Ideas 3.6" in sprints['Sprint2']:
    print(True) 
else:
    print(False)
['Frontend Development', 'Github Pages Playground', 'Javascript Playground', 'SASS Basics']
True
['Big Ideas 3.6', 'Big Ideas 3.7']
True

Popcorn Hack 3

# List of dictionaries representing movies in a movie collection
movie_collection = [
    {
        "title": "Inception",
        "director": "Christopher Nolan",
        "genre": "Sci-Fi",
        "copies_available": 3,
        "viewers": [
            {"name": "John Smith", "view_date": "2024-08-14"},
            {"name": "Jane Doe", "view_date": "2024-09-02"}
        ]
    },
    {
        "title": "The Dark Knight",
        "director": "Christopher Nolan",
        "genre": "Action",
        "copies_available": 2,
        "viewers": [
            {"name": "Bruce Wayne", "view_date": "2024-07-20"}
        ]
    },
    {
        "title": "The Matrix",
        "director": "The Wachowskis",
        "genre": "Sci-Fi",
        "copies_available": 1,
        "viewers": [
            {"name": "Neo Anderson", "view_date": "2024-06-25"}
        ]
    }
]

# Display information about each movie in the movie collection
for movie in movie_collection:
    print(f"Title: {movie['title']}")
    print(f"Director: {movie['director']}")
    print(f"Genre: {movie['genre']}")
    print(f"Copies Available: {movie['copies_available']}")
    print("Viewers:")
    for viewer in movie['viewers']:
        print(f" - {viewer['name']} (Viewed on: {viewer['view_date']})")
    print("\n")

Title: Inception
Director: Christopher Nolan
Genre: Sci-Fi
Copies Available: 3
Viewers:
 - John Smith (Viewed on: 2024-08-14)
 - Jane Doe (Viewed on: 2024-09-02)


Title: The Dark Knight
Director: Christopher Nolan
Genre: Action
Copies Available: 2
Viewers:
 - Bruce Wayne (Viewed on: 2024-07-20)


Title: The Matrix
Director: The Wachowskis
Genre: Sci-Fi
Copies Available: 1
Viewers:
 - Neo Anderson (Viewed on: 2024-06-25)

HW Hack

# List of dictionaries representing soccer matches
soccer_matches = [
    {
        "home_team": "Chelsea",
        "away_team": "Manchester City",
        "date": "2024-09-30",
        "score": "2-1",
        "goal_scorers": [
            {"team": "Chelsea", "scorer": "Raheem Sterling", "minute": 45},
            {"team": "Chelsea", "scorer": "Nicolas Jackson", "minute": 76},
            {"team": "Manchester City", "scorer": "Erling Haaland", "minute": 60}
        ]
    },
    {
        "home_team": "Barcelona",
        "away_team": "Real Madrid",
        "date": "2024-10-07",
        "score": "1-3",
        "goal_scorers": [
            {"team": "Barcelona", "scorer": "Robert Lewandowski", "minute": 22},
            {"team": "Real Madrid", "scorer": "Vinícius Júnior", "minute": 35},
            {"team": "Real Madrid", "scorer": "Karim Benzema", "minute": 55},
            {"team": "Real Madrid", "scorer": "Luka Modrić", "minute": 85}
        ]
    },
    {
        "home_team": "Bayern Munich",
        "away_team": "Borussia Dortmund",
        "date": "2024-10-14",
        "score": "4-0",
        "goal_scorers": [
            {"team": "Bayern Munich", "scorer": "Thomas Müller", "minute": 10},
            {"team": "Bayern Munich", "scorer": "Sadio Mané", "minute": 23},
            {"team": "Bayern Munich", "scorer": "Joshua Kimmich", "minute": 67},
            {"team": "Bayern Munich", "scorer": "Serge Gnabry", "minute": 75}
        ]
    }
]

# Display information about each soccer match
for match in soccer_matches:
    print(f"Match Date: {match['date']}")
    print(f"Home Team: {match['home_team']}")
    print(f"Away Team: {match['away_team']}")
    print(f"Final Score: {match['score']}")
    print("Goal Scorers:")
    for scorer in match['goal_scorers']:
        print(f" - {scorer['team']}: {scorer['scorer']} (Minute: {scorer['minute']})")
    print("\n")

Match Date: 2024-09-30
Home Team: Chelsea
Away Team: Manchester City
Final Score: 2-1
Goal Scorers:
 - Chelsea: Raheem Sterling (Minute: 45)
 - Chelsea: Nicolas Jackson (Minute: 76)
 - Manchester City: Erling Haaland (Minute: 60)


Match Date: 2024-10-07
Home Team: Barcelona
Away Team: Real Madrid
Final Score: 1-3
Goal Scorers:
 - Barcelona: Robert Lewandowski (Minute: 22)
 - Real Madrid: Vinícius Júnior (Minute: 35)
 - Real Madrid: Karim Benzema (Minute: 55)
 - Real Madrid: Luka Modrić (Minute: 85)


Match Date: 2024-10-14
Home Team: Bayern Munich
Away Team: Borussia Dortmund
Final Score: 4-0
Goal Scorers:
 - Bayern Munich: Thomas Müller (Minute: 10)
 - Bayern Munich: Sadio Mané (Minute: 23)
 - Bayern Munich: Joshua Kimmich (Minute: 67)
 - Bayern Munich: Serge Gnabry (Minute: 75)