ACTIVITY 27: Master the Python Dictionaries Data Structures

Photo by RetroSupply on Unsplash

ACTIVITY 27: Master the Python Dictionaries Data Structures

·

79 min read

1. Create 50 Python Files

  • Create 50 Python files, each focusing on dictionary manipulation.

2. GitHub Commit Requirement

  • You must make 50 commits in your GitHub repository, with each commit corresponding to the creation or update of a Python file.

  • Example commit messages:

3. File Requirements

  • Each Python file should involve dictionary manipulation.

4. Create documentation on medium.com or hashnode.com Explain your code and include the github repository link

5. Don't use AI to generate your code. Instead, focus on mastering and understanding list data structures in Python.

1. animal_habitats_dict.py

Creating a dictionary of 8 animals and their natural habitats

animal_habitats_dict = {
    'Lion': 'Savannah',
    'Penguin': 'Antarctica',
    'Kangaroo': 'Australian Outback',
    'Elephant': 'Grasslands',
    'Polar Bear': 'Arctic',
    'Tiger': 'Tropical Rainforest',
    'Panda': 'Bamboo Forests',
    'Whale': 'Ocean'
}
  • A dictionary animal_habitats_dict is created, where each key is the name of an animal (e.g., 'Lion', 'Penguin') and each value is its corresponding habitat (e.g., 'Savannah', 'Antarctica').

  • This dictionary will be used to store the natural habitats of various animals.

Print the entire dictionary

print("The entire dictionary:", animal_habitats_dict)
  • This line prints the entire dictionary to the console, showing all the animals and their corresponding habitats.

Access and print the habitat of the 3rd animal (Kangaroo)

third_animal_habitat = list(animal_habitats_dict.values())[2]  # Index 2 for the 3rd item
print("\nThe habitat of the 3rd animal (Kangaroo):", third_animal_habitat)
  • animal_habitats_dict.values() returns all the values (habitats) in the dictionary.

  • list(animal_habitats_dict.values()) converts those values into a list.

  • list(animal_habitats_dict.values())[2] accesses the habitat of the 3rd animal (using index 2 because Python uses zero-based indexing).

  • The habitat of the 'Kangaroo' (which is 'Australian Outback') is printed.

Update the habitat of the 5th animal (Polar Bear)

animal_habitats_dict['Polar Bear'] = 'Frozen Tundra'
print("\nUpdated habitat of the 5th animal (Polar Bear):", animal_habitats_dict['Polar Bear'])
  • This line updates the habitat of the 'Polar Bear' in the dictionary from 'Arctic' to 'Frozen Tundra'.

  • It then prints the updated habitat of 'Polar Bear' to verify the change.

Delete the 7th animal (Panda) from the dictionary

del animal_habitats_dict['Panda']
print("\nDictionary after deleting the 7th animal (Panda):", animal_habitats_dict)
  • del animal_habitats_dict['Panda'] removes the entry for 'Panda' from the dictionary, effectively deleting this key-value pair.

  • The updated dictionary (without 'Panda') is printed to reflect the deletion.

Print the last key-value pair in the dictionary

last_key = list(animal_habitats_dict.keys())[-1]
last_value = animal_habitats_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(animal_habitats_dict.keys()) converts the dictionary keys (animal names) into a list.

  • [-1] accesses the last key in the list (the last animal).

  • animal_habitats_dict[last_key] retrieves the habitat for the last animal in the dictionary.

  • Finally, it prints the last key-value pair, showing the last animal and its habitat.

2. animal_sounds_dict.py

Creating a dictionary of 8 animals and their corresponding sounds

animal_sounds_dict = {
    'Dog': 'Bark',
    'Cat': 'Meow',
    'Cow': 'Moo',
    'Duck': 'Quack',
    'Sheep': 'Baa',
    'Horse': 'Neigh',
    'Pig': 'Oink',
    'Lion': 'Roar'
}
  • A dictionary named animal_sounds_dict is created, where each key represents an animal (e.g., 'Dog', 'Cat') and each value represents the corresponding sound the animal makes (e.g., 'Bark', 'Meow').

  • This dictionary will be used to store the sounds made by various animals.

Print the entire dictionary

print("The entire dictionary:", animal_sounds_dict)
  • This line prints the entire dictionary to the console, showing all animals and their corresponding sounds.

Access and print the sound of the 4th animal (Duck)

fourth_animal_sound = list(animal_sounds_dict.values())[3]  # Index 3 for the 4th item
print("\nThe sound of the 4th animal (Duck):", fourth_animal_sound)
  • animal_sounds_dict.values() returns all the values (sounds) in the dictionary.

  • list(animal_sounds_dict.values()) converts these values into a list.

  • list(animal_sounds_dict.values())[3] accesses the sound of the 4th animal (using index 3 because Python uses zero-based indexing).

  • The sound of 'Duck' (which is 'Quack') is printed.

Update the sound of the 7th animal (Pig)

animal_sounds_dict['Pig'] = 'Grunt'
print("\nUpdated sound of the 7th animal (Pig):", animal_sounds_dict['Pig'])
  • This line updates the sound of the 'Pig' from 'Oink' to 'Grunt'.

  • It then prints the updated sound of 'Pig' to verify the change.

Delete the 5th animal (Sheep) from the dictionary

del animal_sounds_dict['Sheep']
print("\nDictionary after deleting the 5th animal (Sheep):", animal_sounds_dict)
  • del animal_sounds_dict['Sheep'] removes the entry for 'Sheep' from the dictionary, deleting that key-value pair.

  • The updated dictionary (without 'Sheep') is printed to reflect the deletion.

Print the last key-value pair in the dictionary

last_key = list(animal_sounds_dict.keys())[-1]
last_value = animal_sounds_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(animal_sounds_dict.keys()) converts the dictionary keys (animal names) into a list.

  • [-1] accesses the last key in the list (the last animal).

  • animal_sounds_dict[last_key] retrieves the sound associated with the last animal in the dictionary.

  • Finally, it prints the last key-value pair, showing the last animal and its sound.

3. app_store_ratings_dict.py

Creating a dictionary of 10 apps and their user ratings

app_store_ratings_dict = {
    'WhatsApp': 4.7,
    'Instagram': 4.6,
    'Facebook': 4.4,
    'Snapchat': 4.3,
    'Twitter': 4.2,
    'TikTok': 4.9,
    'YouTube': 4.8,
    'Spotify': 4.5,
    'Messenger': 4.3,
    'Reddit': 4.1
}
  • A dictionary named app_store_ratings_dict is created, where each key represents the name of an app (e.g., 'WhatsApp', 'Instagram') and each value represents the corresponding user rating for that app (e.g., 4.7, 4.6).

  • This dictionary will be used to store the ratings of popular apps.

Print the entire dictionary

print("The entire dictionary:", app_store_ratings_dict)
  • This line prints the entire app_store_ratings_dict to the console, showing all the apps and their user ratings.

Access and print the rating of the 6th app (TikTok)

sixth_app_rating = list(app_store_ratings_dict.values())[5]  # Index 5 for the 6th item
print("\nThe rating of the 6th app (TikTok):", sixth_app_rating)
  • app_store_ratings_dict.values() returns all the values (ratings) in the dictionary.

  • list(app_store_ratings_dict.values()) converts the values into a list.

  • list(app_store_ratings_dict.values())[5] accesses the rating of the 6th app (using index 5 because Python uses zero-based indexing).

  • The rating of 'TikTok' (which is 4.9) is printed.

Update the rating of the 8th app (Spotify)

app_store_ratings_dict['Spotify'] = 4.7  # Updating the rating of Spotify
print("\nUpdated rating of the 8th app (Spotify):", app_store_ratings_dict['Spotify'])
  • This line updates the rating of 'Spotify' from 4.5 to 4.7.

  • It then prints the updated rating of 'Spotify' to verify the change.

Delete the 9th app (Messenger) from the dictionary

del app_store_ratings_dict['Messenger']
print("\nDictionary after deleting the 9th app (Messenger):", app_store_ratings_dict)
  • del app_store_ratings_dict['Messenger'] removes the entry for 'Messenger' from the dictionary, deleting that key-value pair.

  • The updated dictionary (without 'Messenger') is printed to reflect the deletion.

Print the last key-value pair in the dictionary

last_key = list(app_store_ratings_dict.keys())[-1]
last_value = app_store_ratings_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(app_store_ratings_dict.keys()) converts the dictionary keys (app names) into a list.

  • [-1] accesses the last key in the list (the last app).

  • app_store_ratings_dict[last_key] retrieves the rating associated with the last app in the dictionary.

  • Finally, it prints the last key-value pair, showing the last app and its rating.

4. artist_songs_dict.py

Creating a dictionary of 8 artists and their top songs

pythonCopy codeartist_songs_dict = {
    'Taylor Swift': 'Shake It Off',
    'Ed Sheeran': 'Shape of You',
    'Adele': 'Hello',
    'Drake': 'God\'s Plan',
    'Billie Eilish': 'Bad Guy',
    'The Weeknd': 'Blinding Lights',
    'Bruno Mars': 'Uptown Funk',
    'Post Malone': 'Circles'
}
  • A dictionary artist_songs_dict is created, where each key represents an artist's name (e.g., 'Taylor Swift', 'Ed Sheeran') and each value represents the artist’s top song (e.g., 'Shake It Off', 'Shape of You').

  • This dictionary will be used to store the top songs associated with various artists.

Print the entire dictionary

print("The entire dictionary:", artist_songs_dict)
  • This line prints the entire artist_songs_dict to the console, showing all the artists and their corresponding top songs.

Access and print the top song of the 3rd artist (Adele)

third_artist_song = list(artist_songs_dict.values())[2]  # Index 2 for the 3rd artist
print("\nThe top song of the 3rd artist (Adele):", third_artist_song)
  • artist_songs_dict.values() returns all the values (top songs) in the dictionary.

  • list(artist_songs_dict.values()) converts those values into a list.

  • list(artist_songs_dict.values())[2] accesses the top song of the 3rd artist (using index 2 because Python uses zero-based indexing).

  • The top song of 'Adele' (which is 'Hello') is printed.

Update the top song of the 6th artist (The Weeknd)

artist_songs_dict['The Weeknd'] = 'Save Your Tears'  # Updating the top song
print("\nUpdated top song of the 6th artist (The Weeknd):", artist_songs_dict['The Weeknd'])
  • This line updates the top song of 'The Weeknd' from 'Blinding Lights' to 'Save Your Tears'.

  • It then prints the updated top song of 'The Weeknd' to verify the change.

Delete the 7th artist (Bruno Mars) from the dictionary

del artist_songs_dict['Bruno Mars']
print("\nDictionary after deleting the 7th artist (Bruno Mars):", artist_songs_dict)
  • del artist_songs_dict['Bruno Mars'] removes the entry for 'Bruno Mars' from the dictionary, deleting that key-value pair.

  • The updated dictionary (without 'Bruno Mars') is printed to reflect the deletion.

Print the last key-value pair in the dictionary

last_key = list(artist_songs_dict.keys())[-1]
last_value = artist_songs_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(artist_songs_dict.keys()) converts the dictionary keys (artist names) into a list.

  • [-1] accesses the last key in that list (the last artist).

  • artist_songs_dict[last_key] retrieves the top song associated with that last artist in the dictionary.

  • Finally, it prints the last key-value pair, showing the last artist and their top song.

5. athlete_achievements_dict.py

Creating a dictionary of 8 athletes and their greatest achievements

athlete_achievements_dict = {
    'Usain Bolt': 'World record in 100m and 200m sprints',
    'Michael Phelps': 'Winning 23 Olympic gold medals',
    'Serena Williams': '23 Grand Slam singles titles',
    'Cristiano Ronaldo': '5 Ballon d\'Or awards',
    'Simone Biles': '4 Olympic gold medals in gymnastics',
    'LeBron James': '4 NBA championships',
    'Roger Federer': '20 Grand Slam singles titles',
    'Tom Brady': '7 Super Bowl championships'
}
  • A dictionary named athlete_achievements_dict is created where each key is an athlete's name (e.g., 'Usain Bolt', 'Michael Phelps') and each value is a description of the athlete's greatest achievement (e.g., 'World record in 100m and 200m sprints', 'Winning 23 Olympic gold medals').

  • This dictionary will store the major accomplishments of famous athletes.

Print the entire dictionary

print("The entire dictionary:", athlete_achievements_dict)
  • This line prints the entire athlete_achievements_dict to the console, displaying all the athletes and their respective achievements.

Access and print the achievement of the 5th athlete (Simone Biles)

fifth_athlete_achievement = list(athlete_achievements_dict.values())[4]  # Index 4 for the 5th athlete
print("\nThe achievement of the 5th athlete (Simone Biles):", fifth_athlete_achievement)
  • athlete_achievements_dict.values() returns all the values (achievements) in the dictionary.

  • list(athlete_achievements_dict.values()) converts the values into a list.

  • list(athlete_achievements_dict.values())[4] accesses the achievement of the 5th athlete (using index 4, because Python uses zero-based indexing).

  • The achievement of 'Simone Biles' (which is '4 Olympic gold medals in gymnastics') is printed.

Update the achievement of the 3rd athlete (Serena Williams)

athlete_achievements_dict['Serena Williams'] = 'Most Grand Slam singles titles in the Open Era (23 titles)'  # Updating the achievement
print("\nUpdated achievement of the 3rd athlete (Serena Williams):", athlete_achievements_dict['Serena Williams'])
  • This line updates the achievement of 'Serena Williams' from '23 Grand Slam singles titles' to 'Most Grand Slam singles titles in the Open Era (23 titles)' to provide more context and detail.

  • It then prints the updated achievement to verify the change.

Delete the 7th athlete (Roger Federer) from the dictionary

del athlete_achievements_dict['Roger Federer']
print("\nDictionary after deleting the 7th athlete (Roger Federer):", athlete_achievements_dict)
  • del athlete_achievements_dict['Roger Federer'] removes the entry for 'Roger Federer' from the dictionary, deleting that key-value pair.

  • The updated dictionary (without 'Roger Federer') is printed to reflect the deletion.

Print the last key-value pair in the dictionary

last_key = list(athlete_achievements_dict.keys())[-1]
last_value = athlete_achievements_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(athlete_achievements_dict.keys()) converts the dictionary keys (athlete names) into a list.

  • [-1] accesses the last key in the list (the last athlete).

  • athlete_achievements_dict[last_key] retrieves the achievement associated with that last athlete in the dictionary.

  • Finally, it prints the last key-value pair, showing the last athlete and their greatest achievement.

6. author_books_dict.py

Creating a dictionary of 8 authors and their famous books

author_books_dict = {
    'J.K. Rowling': 'Harry Potter and the Sorcerer\'s Stone',
    'George Orwell': '1984',
    'J.R.R. Tolkien': 'The Lord of the Rings',
    'Agatha Christie': 'Murder on the Orient Express',
    'F. Scott Fitzgerald': 'The Great Gatsby',
    'Harper Lee': 'To Kill a Mockingbird',
    'Jane Austen': 'Pride and Prejudice',
    'Mark Twain': 'Adventures of Huckleberry Finn'
}
  • A dictionary named author_books_dict is created. The keys are authors' names (e.g., 'J.K. Rowling', 'George Orwell'), and the values are their most famous books (e.g., 'Harry Potter and the Sorcerer's Stone', '1984').

  • This dictionary helps map authors to their notable works.

Print the entire dictionary

print("The entire dictionary:", author_books_dict)
  • This line prints the entire author_books_dict to the console, showing each author paired with their famous book.

Access and print the book of the 5th author (F. Scott Fitzgerald)

fifth_author_book = list(author_books_dict.values())[4]  # Index 4 for the 5th author
print("\nThe book of the 5th author (F. Scott Fitzgerald):", fifth_author_book)
  • author_books_dict.values() returns all the values (books) in the dictionary.

  • list(author_books_dict.values()) converts those values into a list.

  • list(author_books_dict.values())[4] accesses the 5th item in that list, which corresponds to F. Scott Fitzgerald's book, 'The Great Gatsby'.

  • The book is printed for the 5th author.

Update the book of the 7th author (Jane Austen)

author_books_dict['Jane Austen'] = 'Sense and Sensibility'  # Updating the book
print("\nUpdated book of the 7th author (Jane Austen):", author_books_dict['Jane Austen'])
  • The line updates the book associated with 'Jane Austen'. Originally, the book was 'Pride and Prejudice', but now it is updated to 'Sense and Sensibility'.

  • The updated book for Jane Austen is printed to confirm the change.

Delete the 6th author (Harper Lee) from the dictionary

del author_books_dict['Harper Lee']
print("\nDictionary after deleting the 6th author (Harper Lee):", author_books_dict)
  • del author_books_dict['Harper Lee'] removes the entry for 'Harper Lee' from the dictionary.

  • The updated dictionary, without 'Harper Lee', is printed, reflecting the deletion.

Print the last key-value pair in the dictionary

last_key = list(author_books_dict.keys())[-1]
last_value = author_books_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(author_books_dict.keys()) converts the dictionary keys (author names) into a list.

  • [-1] accesses the last key in the list (the last author).

  • author_books_dict[last_key] retrieves the book associated with the last author in the dictionary.

  • Finally, it prints the last key-value pair, which consists of the last author and their famous book.

7. beaches_countries_dict.py

Creating a dictionary of 8 beaches and the countries they are located in

beaches_countries_dict = {
    'Bondi Beach': 'Australia',
    'Waikiki Beach': 'USA',
    'Copacabana Beach': 'Brazil',
    'Maya Bay': 'Thailand',
    'Santorini Beach': 'Greece',
    'Maldives Beach': 'Maldives',
    'Navagio Beach': 'Greece',
    'Zlatni Rat': 'Croatia'
}
  • A dictionary named beaches_countries_dict is created where the keys are beach names (e.g., 'Bondi Beach', 'Waikiki Beach') and the values are the countries where these beaches are located (e.g., 'Australia', 'USA').

  • This dictionary provides a mapping of some famous beaches to their respective countries.

Print the entire dictionary

print("The entire dictionary:", beaches_countries_dict)
  • This line prints the entire beaches_countries_dict to the console, displaying each beach and its corresponding country.

Access and print the country of the 3rd beach (Copacabana Beach)

third_beach_country = list(beaches_countries_dict.values())[2]  # Index 2 for the 3rd beach
print("\nCountry of the 3rd beach (Copacabana Beach):", third_beach_country)
  • beaches_countries_dict.values() returns all the values (countries) in the dictionary.

  • list(beaches_countries_dict.values()) converts these values into a list.

  • list(beaches_countries_dict.values())[2] accesses the 3rd item in that list (index 2, since Python uses zero-based indexing). This corresponds to the country of 'Copacabana Beach', which is 'Brazil'.

  • The country of the 3rd beach is printed.

Update the country of the 6th beach (Maldives Beach)

beaches_countries_dict['Maldives Beach'] = 'Sri Lanka'
print("\nUpdated country of the 6th beach (Maldives Beach):", beaches_countries_dict['Maldives Beach'])
  • This line updates the country associated with 'Maldives Beach' from 'Maldives' to 'Sri Lanka'.

  • It then prints the updated country for 'Maldives Beach' to confirm the change.

Delete the 5th beach (Santorini Beach) from the dictionary

del beaches_countries_dict['Santorini Beach']
print("\nDictionary after deleting the 5th beach (Santorini Beach):", beaches_countries_dict)
  • del beaches_countries_dict['Santorini Beach'] removes the entry for 'Santorini Beach' from the dictionary.

  • The updated dictionary (without 'Santorini Beach') is printed to reflect the deletion.

Print the last key-value pair in the dictionary

last_key = list(beaches_countries_dict.keys())[-1]
last_value = beaches_countries_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(beaches_countries_dict.keys()) converts the dictionary keys (beach names) into a list.

  • [-1] accesses the last key in the list (the last beach).

  • beaches_countries_dict[last_key] retrieves the country associated with that last beach.

  • Finally, the last key-value pair (the last beach and its country) is printed.

8. book_authors_dict.py

Creating a dictionary of 12 books and their authors

book_authors_dict = {
    '1984': 'George Orwell',
    'To Kill a Mockingbird': 'Harper Lee',
    'The Great Gatsby': 'F. Scott Fitzgerald',
    'Moby-Dick': 'Herman Melville',
    'Pride and Prejudice': 'Jane Austen',
    'War and Peace': 'Leo Tolstoy',
    'The Catcher in the Rye': 'J.D. Salinger',
    'The Hobbit': 'J.R.R. Tolkien',
    'The Lord of the Rings': 'J.R.R. Tolkien',
    'Crime and Punishment': 'Fyodor Dostoevsky',
    'Brave New World': 'Aldous Huxley',
    'Frankenstein': 'Mary Shelley'
}
  • A dictionary named book_authors_dict is created, where the keys are book titles (e.g., '1984', 'To Kill a Mockingbird'), and the values are the corresponding authors (e.g., 'George Orwell', 'Harper Lee').

  • This dictionary maps classic books to their authors.

Print the entire dictionary

print("The entire dictionary:", book_authors_dict)
  • This line prints the entire book_authors_dict to the console, showing each book and its associated author.

Access and print the author of the 9th book (The Lord of the Rings)

ninth_book_author = list(book_authors_dict.values())[8]  # Index 8 for the 9th item
print("\nThe author of the 9th book (The Lord of the Rings):", ninth_book_author)
  • book_authors_dict.values() returns all the values (authors) in the dictionary.

  • list(book_authors_dict.values()) converts the values into a list.

  • list(book_authors_dict.values())[8] accesses the 9th item (since Python uses zero-based indexing, index 8 corresponds to the 9th book), which is the author of 'The Lord of the Rings'.

  • The author of the 9th book is printed (in this case, 'J.R.R. Tolkien').

Update the author of the 5th book (Pride and Prejudice)

book_authors_dict['Pride and Prejudice'] = 'Updated Author'
print("\nUpdated author of the 5th book (Pride and Prejudice):", book_authors_dict['Pride and Prejudice'])
  • This line updates the author of the book 'Pride and Prejudice' from 'Jane Austen' to 'Updated Author'.

  • The updated author for 'Pride and Prejudice' is printed to confirm the change.

Delete the 3rd book (The Great Gatsby) from the dictionary

del book_authors_dict['The Great Gatsby']
print("\nDictionary after deleting the 3rd book (The Great Gatsby):", book_authors_dict)
  • del book_authors_dict['The Great Gatsby'] removes the entry for 'The Great Gatsby' from the dictionary.

  • The updated dictionary, after deleting 'The Great Gatsby', is printed, showing the change.

Print the last key-value pair in the dictionary

last_key = list(book_authors_dict.keys())[-1]
last_value = book_authors_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(book_authors_dict.keys()) converts the dictionary keys (book titles) into a list.

  • [-1] accesses the last key in that list (the last book).

  • book_authors_dict[last_key] retrieves the author of the last book in the dictionary.

  • Finally, it prints the last key-value pair (the last book and its author).

9. car_brands_dict.py

Creating a dictionary of 10 car brands and their country of origin

car_brands_dict = {
    'Toyota': 'Japan',
    'BMW': 'Germany',
    'Ford': 'USA',
    'Chevrolet': 'USA',
    'Audi': 'Germany',
    'Honda': 'Japan',
    'Hyundai': 'South Korea',
    'Nissan': 'Japan',
    'Kia': 'South Korea',
    'Ferrari': 'Italy'
}
  • The dictionary car_brands_dict is created, where the keys are car brand names (e.g., 'Toyota', 'BMW') and the values are the countries of origin for each brand (e.g., 'Japan', 'Germany').

Print the entire dictionary

print("The entire dictionary:", car_brands_dict)
  • This line prints the entire car_brands_dict, showing all car brands and their respective countries of origin.

Access and print the country of origin of the 3rd car brand (Ford)

third_car_country = list(car_brands_dict.values())[2]  # Index 2 for the 3rd item
print("\nThe country of origin of the 3rd car brand (Ford):", third_car_country)
  • car_brands_dict.values() gives all the values (countries of origin) of the dictionary.

  • list(car_brands_dict.values()) converts these values into a list.

  • list(car_brands_dict.values())[2] accesses the 3rd item in this list (which corresponds to the country of origin for 'Ford').

  • The country of origin for 'Ford' (USA) is printed.

Update the country of origin of the 7th car brand (Hyundai)

car_brands_dict['Hyundai'] = 'South Korea (Updated)'
print("\nUpdated country of origin of the 7th car brand (Hyundai):", car_brands_dict['Hyundai'])
  • This line updates the country of origin for 'Hyundai' from 'South Korea' to 'South Korea (Updated)'.

  • The updated country of origin for 'Hyundai' is then printed.

Delete the 8th car brand (Nissan) from the dictionary

del car_brands_dict['Nissan']
print("\nDictionary after deleting the 8th car brand (Nissan):", car_brands_dict)
  • del car_brands_dict['Nissan'] removes the entry for 'Nissan' from the dictionary.

  • The updated dictionary, after deleting 'Nissan', is printed to confirm the change.

Print the last key-value pair in the dictionary

last_key = list(car_brands_dict.keys())[-1]
last_value = car_brands_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(car_brands_dict.keys()) converts the dictionary keys (car brands) into a list.

  • [-1] accesses the last key (the last car brand) in that list.

  • car_brands_dict[last_key] retrieves the country of origin for that last car brand.

  • Finally, the last key-value pair (car brand and its country of origin) is printed.

10. car_specs_dict.py

Creating a dictionary of 10 car models and their engine specifications

car_specs_dict = {
    'Toyota Corolla': '1.8L 4-Cylinder, 139 hp',
    'Honda Civic': '2.0L 4-Cylinder, 158 hp',
    'Ford Mustang': '5.0L V8, 450 hp',
    'Chevrolet Camaro': '6.2L V8, 455 hp',
    'BMW 3 Series': '2.0L 4-Cylinder Turbo, 255 hp',
    'Audi A4': '2.0L 4-Cylinder Turbo, 188 hp',
    'Mercedes-Benz C-Class': '2.0L 4-Cylinder Turbo, 255 hp',
    'Tesla Model 3': 'Electric, 283 hp',
    'Nissan Altima': '2.5L 4-Cylinder, 188 hp',
    'Volkswagen Jetta': '1.4L 4-Cylinder Turbo, 147 hp'
}
  • A dictionary car_specs_dict is created with car models as keys (e.g., 'Toyota Corolla', 'Honda Civic') and their engine specifications as values (e.g., '1.8L 4-Cylinder, 139 hp', '2.0L 4-Cylinder, 158 hp').

Print the entire dictionary

print("The entire dictionary:", car_specs_dict)
  • This line prints the entire car_specs_dict, showing all the car models and their engine specifications.

Access and print the specifications of the 4th car model (Chevrolet Camaro)

fourth_car_specs = list(car_specs_dict.values())[3]  # Index 3 for the 4th car model
print("\nThe specifications of the 4th car model (Chevrolet Camaro):", fourth_car_specs)
  • car_specs_dict.values() gives all the values (engine specifications) in the dictionary.

  • list(car_specs_dict.values()) converts these values into a list.

  • list(car_specs_dict.values())[3] accesses the 4th item in this list, which corresponds to the engine specifications of 'Chevrolet Camaro'.

  • The engine specifications for 'Chevrolet Camaro' are printed.

Update the specifications of the 9th car model (Nissan Altima)

car_specs_dict['Nissan Altima'] = '2.5L 4-Cylinder, 190 hp'  # Updating the specifications
print("\nUpdated specifications of the 9th car model (Nissan Altima):", car_specs_dict['Nissan Altima'])
  • This line updates the specifications of 'Nissan Altima' in the dictionary, changing its engine details from '2.5L 4-Cylinder, 188 hp' to '2.5L 4-Cylinder, 190 hp'.

  • The updated specifications for 'Nissan Altima' are then printed.

Delete the 5th car model (BMW 3 Series) from the dictionary

del car_specs_dict['BMW 3 Series']
print("\nDictionary after deleting the 5th car model (BMW 3 Series):", car_specs_dict)
  • del car_specs_dict['BMW 3 Series'] removes the entry for 'BMW 3 Series' from the dictionary.

  • The updated dictionary, after deleting 'BMW 3 Series', is printed to show the remaining car models and their specifications.

Print the last key-value pair in the dictionary

last_key = list(car_specs_dict.keys())[-1]
last_value = car_specs_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(car_specs_dict.keys()) converts the dictionary keys (car models) into a list.

  • [-1] accesses the last key (car model) in that list.

  • car_specs_dict[last_key] retrieves the engine specifications for that last car model.

  • Finally, the last key-value pair (car model and its engine specifications) is printed.

11.city_landmarks_dict.py

Creating the dictionary:

city_landmarks_dict = {
    'Paris': 'Eiffel Tower',
    'New York': 'Statue of Liberty',
    'Rome': 'Colosseum',
    'London': 'Big Ben',
    'Tokyo': 'Tokyo Tower',
    'Cairo': 'Pyramids of Giza',
    'Sydney': 'Sydney Opera House',
    'Beijing': 'Great Wall of China'
}
  • This dictionary city_landmarks_dict contains 8 cities as keys (e.g., 'Paris', 'New York', 'Rome', etc.) and their corresponding famous landmarks as values (e.g., 'Eiffel Tower', 'Statue of Liberty', etc.).

Printing the entire dictionary:

print("The entire dictionary:", city_landmarks_dict)
  • This line prints the entire city_landmarks_dict, displaying each city alongside its landmark.

Accessing and printing the landmark of the 6th city (Cairo):

sixth_city_landmark = list(city_landmarks_dict.values())[5]  # Index 5 for the 6th city
print("\nThe landmark of the 6th city (Cairo):", sixth_city_landmark)
  • city_landmarks_dict.values() retrieves all the values (landmarks) from the dictionary.

  • list(city_landmarks_dict.values()) converts the values into a list.

  • list(city_landmarks_dict.values())[5] accesses the 6th item in the list (Cairo), which is "Pyramids of Giza".

  • The landmark of Cairo is then printed.

Updating the landmark of the 2nd city (New York):

city_landmarks_dict['New York'] = 'Empire State Building'  # Updating the landmark
print("\nUpdated landmark of the 2nd city (New York):", city_landmarks_dict['New York'])
  • The landmark for 'New York' is updated from 'Statue of Liberty' to 'Empire State Building'.

  • The updated landmark of New York is printed.

Deleting the 7th city (Sydney) from the dictionary:

del city_landmarks_dict['Sydney']
print("\nDictionary after deleting the 7th city (Sydney):", city_landmarks_dict)
  • The entry for 'Sydney' is removed from the dictionary using the del statement.

  • The dictionary is printed again to show the result after the deletion of 'Sydney'.

Printing the last key-value pair in the dictionary:

last_key = list(city_landmarks_dict.keys())[-1]
last_value = city_landmarks_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(city_landmarks_dict.keys()) converts the dictionary keys (cities) into a list.

  • [-1] accesses the last key (city) in the list.

  • city_landmarks_dict[last_key] retrieves the landmark of that last city.

  • Finally, the last key-value pair (city and its landmark) is printed.

12.city_population_dict.py

Creating the dictionary of cities and populations:

city_population_dict = {
    'New York': 8419600,
    'Los Angeles': 3980400,
    'Chicago': 2716000,
    'Houston': 2328000,
    'Phoenix': 1690000,
    'Philadelphia': 1584200,
    'San Antonio': 1547250,
    'San Diego': 1423851,
    'Dallas': 1341075,
    'San Jose': 1026908
}
  • The dictionary city_population_dict stores the names of 10 cities as keys and their respective populations as values.

Printing the entire dictionary:

print("The entire dictionary:", city_population_dict)
  • This line prints the entire dictionary, showing each city along with its population.

Accessing and printing the population of the 6th city (Philadelphia):

sixth_city_population = list(city_population_dict.values())[5]  # Index 5 for the 6th item
print("\nThe population of the 6th city (Philadelphia):", sixth_city_population)
  • city_population_dict.values() retrieves the list of population values.

  • list(city_population_dict.values())[5] accesses the 6th item in the list (Philadelphia's population, which is 1584200).

  • This population is printed.

Updating the population of the 3rd city (Chicago):

city_population_dict['Chicago'] = 2800000
print("\nUpdated population of the 3rd city (Chicago):", city_population_dict['Chicago'])
  • The population of Chicago is updated from 2716000 to 2800000.

  • The updated population of Chicago is then printed.

Deleting the 9th city (Dallas) from the dictionary:

del city_population_dict['Dallas']
print("\nDictionary after deleting the 9th city (Dallas):", city_population_dict)
  • The del statement removes 'Dallas' from the dictionary.

  • The dictionary is printed again to show the result after the deletion.

Printing the last key-value pair in the dictionary:

last_key = list(city_population_dict.keys())[-1]
last_value = city_population_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • list(city_population_dict.keys()) converts the dictionary keys (city names) into a list.

  • [-1] accesses the last city in the list.

  • city_population_dict[last_key] retrieves the population of the last city in the dictionary.

  • The last key-value pair (city and population) is printed.

13.coffee_types_dict.py

Creating the coffee types dictionary

  • The dictionary coffee_types_dict holds the names of 10 coffee types as keys and their descriptions as values.

      coffee_types_dict = {
          'Espresso': 'A strong, black coffee brewed by forcing hot water through finely-ground coffee beans.',
          'Americano': 'A diluted espresso, made by adding hot water to espresso, resulting in a less intense flavor.',
          'Latte': 'A coffee drink made with espresso and steamed milk, topped with a small amount of foam.',
          'Cappuccino': 'A coffee drink made with equal parts espresso, steamed milk, and milk foam.',
          'Macchiato': 'An espresso with a small amount of steamed milk, leaving a "stain" or "mark" on the coffee.',
          'Mocha': 'A coffee drink made with espresso, steamed milk, and chocolate syrup or cocoa powder.',
          'Flat White': 'A coffee drink made with espresso and steamed milk, similar to a latte but with a higher ratio of coffee to milk.',
          'Affogato': 'A dessert coffee made by pouring hot espresso over a scoop of vanilla ice cream.',
          'Cortado': 'A coffee drink made with equal parts espresso and warm milk, typically served in a small glass.',
          'Irish Coffee': 'A cocktail made with hot coffee, Irish whiskey, sugar, and topped with cream.'
      }
    

    Printing the entire dictionar

  • This command prints all coffee types and their descriptions.

      print("The entire dictionary:", coffee_types_dict)
    

    Accessing and printing the description of the 4th coffee type (Cappuccino)

  • The 4th coffee type (Cappuccino) is accessed using its index, and its description is printed.

      fourth_coffee_description = list(coffee_types_dict.values())[3]  # Index 3 for the 4th type
      print("\nDescription of the 4th type of coffee (Cappuccino):", fourth_coffee_description)
    

    Updating the description of the 8th coffee type (Affogato)

  • The description of Affogato is updated to a new one, and the updated description is printed.

      coffee_types_dict['Affogato'] = 'A dessert made by pouring hot espresso over a scoop of ice cream or gelato.'
      print("\nUpdated description of the 8th type of coffee (Affogato):", coffee_types_dict['Affogato'])
    

    Deleting the 5th coffee type (Macchiato)

  • The del statement deletes the key-value pair corresponding to 'Macchiato'.

      del coffee_types_dict['Macchiato']
      print("\nDictionary after deleting the 5th type of coffee (Macchiato):", coffee_types_dict)
    

    Printing the last key-value pair in the dictionary

  • The last key-value pair (the final coffee type and its description) is accessed and printed.

      last_key = list(coffee_types_dict.keys())[-1]
      last_value = coffee_types_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

14.company_ceos_dict.py

Creating the company CEOs dictionary

  • The dictionary company_ceos_dict contains the names of 10 companies as keys and their current CEOs as values.

      pythonCopy codecompany_ceos_dict = {
          'Apple': 'Tim Cook',
          'Microsoft': 'Satya Nadella',
          'Amazon': 'Andy Jassy',
          'Google': 'Sundar Pichai',
          'Facebook': 'Mark Zuckerberg',
          'Tesla': 'Elon Musk',
          'Netflix': 'Reed Hastings',
          'Samsung': 'Kim Hyun Suk',
          'Adobe': 'Shantanu Narayen',
          'Intel': 'Pat Gelsinger'
      }
    

    Printing the entire dictionary

  • This command prints all companies and their respective CEOs.

      print("The entire dictionary:", company_ceos_dict)
    

    Accessing and printing the CEO of the 6th company (Tesla)

  • The CEO of Tesla (6th company in the dictionary) is accessed using its index and printed.

      sixth_company_ceo = list(company_ceos_dict.values())[5]  # Index 5 for the 6th item
      print("\nThe CEO of the 6th company (Tesla):", sixth_company_ceo)
    

    Updating the CEO of the 3rd company (Amazon)

  • The CEO of Amazon is updated to 'Jeff Bezos' (as of the previous CEO before Andy Jassy), and the updated value is printed.

      company_ceos_dict['Amazon'] = 'Jeff Bezos'  # Updating CEO of Amazon
      print("\nUpdated CEO of the 3rd company (Amazon):", company_ceos_dict['Amazon'])
    

    Deleting the 9th company (Adobe)

  • The del statement is used to delete the key-value pair corresponding to 'Adobe' from the dictionary.

      del company_ceos_dict['Adobe']
      print("\nDictionary after deleting the 9th company (Adobe):", company_ceos_dict)
    

    Printing the last key-value pair in the dictionary

  • The last company and its CEO are accessed and printed using the last index of the keys and values.

      last_key = list(company_ceos_dict.keys())[-1]
      last_value = company_ceos_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

15.company_founders_dict.py

Creating the company_founders_dict

  • The dictionary stores the names of companies as keys and their founders as values.

      company_founders_dict = {
          'Apple': 'Steve Jobs',
          'Microsoft': 'Bill Gates',
          'Tesla': 'Elon Musk',
          'Amazon': 'Jeff Bezos',
          'Facebook': 'Mark Zuckerberg',
          'Google': 'Larry Page and Sergey Brin',
          'Twitter': 'Jack Dorsey',
          'SpaceX': 'Elon Musk'
      }
    

    Printing the entire dictionary

  • The command below prints all the company-founder pairs.

      print("The entire dictionary:", company_founders_dict)
    

    Accessing and printing the founder of the 6th company (Google)

  • Google is the 6th company in the dictionary. We access it using its index and print the corresponding founder.

      sixth_company_founder = list(company_founders_dict.values())[5]  # Index 5 for the 6th company
      print("\nThe founder of the 6th company (Google):", sixth_company_founder)
    

    Updating the founder of the 2nd company (Microsoft)

  • The founder of Microsoft is updated from "Bill Gates" to "Paul Allen" using the dictionary key.

      company_founders_dict['Microsoft'] = 'Paul Allen'  # Updating the founder
      print("\nUpdated founder of the 2nd company (Microsoft):", company_founders_dict['Microsoft'])
    

    Deleting the 8th company (SpaceX)

  • The del statement removes the key-value pair for SpaceX from the dictionary.

      del company_founders_dict['SpaceX']
      print("\nDictionary after deleting the 8th company (SpaceX):", company_founders_dict)
    

    Printing the last key-value pair in the dictionary

  • The last company-founder pair is accessed using the last index and printed.

      last_key = list(company_founders_dict.keys())[-1]
      last_value = company_founders_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

16.continent_countries_dict.py

Creating the continent_countries_dict

  • This dictionary holds the names of continents as keys, and each key maps to a list of countries within that continent.

      continent_countries_dict = {
          'Africa': ['Nigeria', 'Egypt', 'South Africa'],
          'Asia': ['China', 'India', 'Japan'],
          'Europe': ['Germany', 'France', 'Italy'],
          'North America': ['USA', 'Canada', 'Mexico'],
          'South America': ['Brazil', 'Argentina', 'Colombia'],
          'Australia': ['Australia', 'New Zealand', 'Papua New Guinea']
      }
    

    Printing the entire dictionary

  • The dictionary is printed in its entirety:

      print("The entire dictionary:", continent_countries_dict)
    

    Accessing and printing the countries of the 4th continent (North America)

  • The countries of North America are accessed by using its key, 'North America', and printed:

      fourth_continent_countries = continent_countries_dict['North America']
      print("\nThe countries of the 4th continent (North America):", fourth_continent_countries)
    

    Updating the countries of the 5th continent (South America)

  • The list of countries for South America is updated from ['Brazil', 'Argentina', 'Colombia'] to ['Chile', 'Peru', 'Venezuela']:

      continent_countries_dict['South America'] = ['Chile', 'Peru', 'Venezuela']
      print("\nUpdated countries of the 5th continent (South America):", continent_countries_dict['South America'])
    

    Deleting the 6th continent (Australia)

  • The entire entry for Australia is removed from the dictionary using the del statement:

      del continent_countries_dict['Australia']
      print("\nDictionary after deleting the 6th continent (Australia):", continent_countries_dict)
    

    Printing the last key-value pair in the dictionary

  • The last continent and its associated countries are accessed using the last key in the dictionary:

      last_key = list(continent_countries_dict.keys())[-1]
      last_value = continent_countries_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

17.country_capital_dict.py

Creating the country_capital_dict

  • This dictionary holds country names as keys and their corresponding capitals as values:

      pythonCopy codecountry_capital_dict = {
          'United States': 'Washington, D.C.',
          'Canada': 'Ottawa',
          'Mexico': 'Mexico City',
          'Brazil': 'Brasília',
          'United Kingdom': 'London',
          'France': 'Paris',
          'Germany': 'Berlin',
          'Italy': 'Rome',
          'Spain': 'Madrid',
          'Australia': 'Canberra',
          'Japan': 'Tokyo',
          'India': 'New Delhi'
      }
    

    Printing the entire dictionary

  • The entire dictionary is printed, displaying each country and its capital:

      print("The entire dictionary:", country_capital_dict)
    

    Accessing and printing the capital of the 5th country (United Kingdom)

  • The capital of the United Kingdom is accessed by using its position (index 4, as lists are zero-indexed) in the dictionary:

      fifth_country_capital = list(country_capital_dict.values())[4]
      print("\nThe capital of the 5th country (United Kingdom):", fifth_country_capital)
    

    Updating the capital of the 8th country (Italy)

  • The capital of Italy is updated from 'Rome' to 'Milan':

      country_capital_dict['Italy'] = 'Milan'
      print("\nUpdated capital of the 8th country (Italy):", country_capital_dict['Italy'])
    

    Deleting the 11th country (Japan) from the dictionary

  • The entry for Japan, including its capital, is deleted using the del statement:

      del country_capital_dict['Japan']
      print("\nDictionary after deleting the 11th country (Japan):", country_capital_dict)
    

    Printing the last key-value pair in the dictionary

  • The last key-value pair in the dictionary (after the deletion of Japan) is printed:

      last_key = list(country_capital_dict.keys())[-1]
      last_value = country_capital_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

18.currency_symbols_dict.py

  • Creating the currency_symbols_dict: The dictionary currency_symbols_dict holds currency codes as keys and their corresponding symbols as values:

      currency_symbols_dict = {
          'USD': '$',
          'EUR': '€',
          'GBP': '£',
          'JPY': '¥',
          'AUD': '$',
          'CAD': '$',
          'CHF': 'Fr.',
          'INR': '₹',
          'CNY': '¥',
          'MXN': '$'
      }
    
  • Printing the entire dictionary: The entire dictionary is printed, displaying the currency codes and their symbols:

      print("The entire dictionary:", currency_symbols_dict)
    
  • Accessing and printing the symbol of the 5th currency (AUD): The symbol for the 5th currency (AUD) is accessed using its index (index 4, since lists are zero-indexed) and printed:

      fifth_currency_symbol = list(currency_symbols_dict.values())[4]
      print("\nThe symbol of the 5th currency (AUD):", fifth_currency_symbol)
    
  • Updating the symbol of the 9th currency (CNY): The symbol for the Chinese Yuan (CNY) is updated from '¥' to '元':

      currency_symbols_dict['CNY'] = '元'
      print("\nUpdated symbol of the 9th currency (CNY):", currency_symbols_dict['CNY'])
    
  • Deleting the 3rd currency (GBP) from the dictionary: The entry for the British Pound (GBP) is deleted from the dictionary:

      del currency_symbols_dict['GBP']
      print("\nDictionary after deleting the 3rd currency (GBP):", currency_symbols_dict)
    
  • Printing the last key-value pair in the dictionary: After the deletion of GBP, the last key-value pair in the dictionary is printed:

      last_key = list(currency_symbols_dict.keys())[-1]
      last_value = currency_symbols_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

19.dinosaur_fossils_dict.py

  • Creating the dinosaur_fossils_dict: A dictionary dinosaur_fossils_dict is created where the keys are dinosaur species and the values are the locations where their fossils were found.

      dinosaur_fossils_dict = {
          'Tyrannosaurus Rex': 'North America',
          'Velociraptor': 'Mongolia',
          'Triceratops': 'North America',
          'Brachiosaurus': 'Africa',
          'Stegosaurus': 'North America',
          'Allosaurus': 'North America',
          'Spinosaurus': 'North Africa'
      }
    
  • Printing the entire dictionary: The entire dictionary is printed, displaying the dinosaur names and their fossil locations.

      print("The entire dictionary:", dinosaur_fossils_dict)
    
  • Accessing and printing the location of the 4th dinosaur's fossils (Brachiosaurus): The location for the fossils of the 4th dinosaur (Brachiosaurus) is accessed using index 3 (since indexing starts from 0) and printed.

      fourth_dinosaur_location = list(dinosaur_fossils_dict.values())[3]
      print("\nThe location of the 4th dinosaur's fossils (Brachiosaurus):", fourth_dinosaur_location)
    
  • Updating the location of the 2nd dinosaur's fossils (Velociraptor): The location for the fossils of the Velociraptor is updated from 'Mongolia' to 'China'.

      dinosaur_fossils_dict['Velociraptor'] = 'China'
      print("\nUpdated location of the 2nd dinosaur's fossils (Velociraptor):", dinosaur_fossils_dict['Velociraptor'])
    
  • Deleting the 6th dinosaur (Allosaurus) from the dictionary: The entry for the Allosaurus is deleted from the dictionary.

      del dinosaur_fossils_dict['Allosaurus']
      print("\nDictionary after deleting the 6th dinosaur (Allosaurus):", dinosaur_fossils_dict)
    
  • Printing the last key-value pair in the dictionary: After the deletion of Allosaurus, the last key-value pair in the dictionary is printed.

      last_key = list(dinosaur_fossils_dict.keys())[-1]
      last_value = dinosaur_fossils_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

20.dog_breeds_dict.py

  • Creating the dog_breeds_dict: A dictionary is created where the keys are dog breeds and the values are their respective sizes.

      dog_breeds_dict = {
          'Chihuahua': 'Small',
          'Beagle': 'Medium',
          'Labrador Retriever': 'Large',
          'German Shepherd': 'Large',
          'Bulldog': 'Medium',
          'Poodle': 'Medium',
          'Golden Retriever': 'Large',
          'Cocker Spaniel': 'Medium',
          'Boxer': 'Large',
          'Dachshund': 'Small'
      }
    
  • Printing the entire dictionary: The entire dictionary is printed, showing the dog breeds and their corresponding sizes.

      print("The entire dictionary:", dog_breeds_dict)
    
  • Accessing and printing the size of the 5th breed (Bulldog): The size for the Bulldog (the 5th breed in the list) is accessed using index 4 and printed.

      fifth_breed_size = list(dog_breeds_dict.values())[4]
      print("\nThe size of the 5th breed (Bulldog):", fifth_breed_size)
    
  • Updating the size of the 8th breed (Cocker Spaniel): The size of the Cocker Spaniel is updated from 'Medium' to 'Small'.

      dog_breeds_dict['Cocker Spaniel'] = 'Small'
      print("\nUpdated size of the 8th breed (Cocker Spaniel):", dog_breeds_dict['Cocker Spaniel']
    
  • Deleting the 6th breed (Poodle) from the dictionary: The Poodle breed is deleted from the dictionary.

      del dog_breeds_dict['Poodle']
      print("\nDictionary after deleting the 6th breed (Poodle):", dog_breeds_dict)
    
  • Printing the last key-value pair in the dictionary: After the deletion of the Poodle, the last key-value pair in the dictionary is printed.

      last_key = list(dog_breeds_dict.keys())[-1]
      last_value = dog_breeds_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

21.element_symbols_dict.py

  • Creating the element_symbols_dict: This dictionary maps chemical elements to their corresponding chemical symbols.

      element_symbols_dict = {
          'Hydrogen': 'H',
          'Helium': 'He',
          'Lithium': 'Li',
          'Beryllium': 'Be',
          'Boron': 'B',
          'Carbon': 'C',
          'Nitrogen': 'N',
          'Oxygen': 'O',
          'Fluorine': 'F',
          'Neon': 'Ne'
      }
    
  • Printing the entire dictionary: The dictionary is printed in its entirety, showing each element and its symbol.

      print("The entire dictionary:", element_symbols_dict)
    
  • Accessing and printing the symbol of the 6th element (Carbon): The symbol for Carbon (the 6th element in the dictionary) is accessed by its index (index 5) and printed.

      sixth_element_symbol = list(element_symbols_dict.values())[5]
      print("\nThe symbol of the 6th element (Carbon):", sixth_element_symbol)
    
  • Updating the symbol of the 8th element (Oxygen): The symbol of Oxygen is updated from 'O' to 'O2' (representing the molecular form of oxygen).

      element_symbols_dict['Oxygen'] = 'O2'
      print("\nUpdated symbol of the 8th element (Oxygen):", element_symbols_dict['Oxygen'])
    
  • Deleting the 9th element (Fluorine) from the dictionary: The entry for Fluorine is deleted from the dictionary.

      del element_symbols_dict['Fluorine']
      print("\nDictionary after deleting the 9th element (Fluorine):", element_symbols_dict)
    
  • Printing the last key-value pair in the dictionary: After deleting Fluorine, the last key-value pair in the dictionary is printed.

      last_key = list(element_symbols_dict.keys())[-1]
      last_value = element_symbols_dict[last_key]
      print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
    

22.festival_dates_dict.py

Creating the Dictionary of Festivals and Dates

festival_dates_dict = {
    'Diwali': 'November 12, 2023',
    'Christmas': 'December 25, 2023',
    'Easter': 'April 9, 2023',
    'Halloween': 'October 31, 2023',
    'Thanksgiving': 'November 23, 2023',
    'New Year': 'January 1, 2024',
    'Lunar New Year': 'February 10, 2024',
    'Holi': 'March 25, 2024',
    'Ramadan': 'March 11, 2024',
    'Oktoberfest': 'September 21, 2024'
}
  • Purpose: A dictionary named festival_dates_dict is created to store festival names as keys and their corresponding celebration dates as values.

  • The dictionary contains 10 festival names with their respective celebration dates, such as 'Diwali' as the key and 'November 12, 2023' as the value.

Printing the Entire Dictionary

print("The entire dictionary:", festival_dates_dict)
  • Purpose: This line prints the entire dictionary to the console.

  • It shows all the festival names (keys) and their corresponding dates (values) stored in the festival_dates_dict.

Accessing and Printing the Date of the 3rd Festival (Easter)

third_festival_date = list(festival_dates_dict.values())[2]  # Index 2 for the 3rd festival
print("\nThe date of the 3rd festival (Easter):", third_festival_date)
  • Purpose: This code retrieves and prints the date of the 3rd festival in the dictionary (which is Easter).

  • Step-by-step explanation:

    • festival_dates_dict.values() returns a list of all the values in the dictionary (the celebration dates).

    • list(festival_dates_dict.values())[2] converts those values into a list and accesses the value at index 2 (which corresponds to the 3rd entry, Easter).

    • This date, April 9, 2023, is printed as the date of the 3rd festival (Easter).

Updating the Date of the 7th Festival (Lunar New Year)

festival_dates_dict['Lunar New Year'] = 'February 14, 2024'  # Updating the date
print("\nUpdated date of the 7th festival (Lunar New Year):", festival_dates_dict['Lunar New Year'])
  • Purpose: This updates the date of the Lunar New Year festival in the dictionary to 'February 14, 2024'.

  • Step-by-step explanation:

    • The dictionary is updated by assigning a new date ('February 14, 2024') to the key 'Lunar New Year'.

    • After the update, the new date is printed.

Deleting the 5th Festival (Thanksgiving) from the Dictionary

del festival_dates_dict['Thanksgiving']
print("\nDictionary after deleting the 5th festival (Thanksgiving):", festival_dates_dict)
  • Purpose: This deletes the key-value pair for the Thanksgiving festival from the dictionary.

  • Step-by-step explanation:

    • del festival_dates_dict['Thanksgiving'] removes the entry for Thanksgiving from the dictionary.

    • After deletion, the updated dictionary (without the Thanksgiving entry) is printed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(festival_dates_dict.keys())[-1]
last_value = festival_dates_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This retrieves and prints the last key-value pair in the dictionary.

  • Step-by-step explanation:

    • festival_dates_dict.keys() returns all the keys (festival names) as a view object.

    • list(festival_dates_dict.keys()) converts the view object into a list.

    • [-1] accesses the last element of the list (i.e., the last key in the dictionary).

    • festival_dates_dict[last_key] retrieves the value (date) associated with the last festival key.

    • The last key-value pair is printed in the format (key, value).

23.festival_locations_dict.py

Creating the Dictionary of Festivals and Locations

pythonCopy codefestival_locations_dict = {
    'Diwali': 'India',
    'Carnival': 'Brazil',
    'Oktoberfest': 'Germany',
    'Mardi Gras': 'USA',
    'Songkran': 'Thailand',
    'La Tomatina': 'Spain',
    'Holi': 'India',
    'Glastonbury': 'UK'
}
  • Purpose: This creates a dictionary called festival_locations_dict that stores festival names as keys and their respective locations (countries) as values.

  • The dictionary contains 8 festival names and their corresponding locations, for example:

    • 'Diwali' is celebrated in 'India'.

    • 'Carnival' is celebrated in 'Brazil', and so on.

Printing the Entire Dictionary

print("The entire dictionary:")
print(festival_locations_dict)
  • Purpose: This line prints the entire dictionary, displaying all the festivals and their corresponding locations.

Accessing and Printing the Location of the 4th Festival (Mardi Gras)

fourth_festival_location = list(festival_locations_dict.values())[3]  # Index 3 for the 4th festival
print("\nLocation of the 4th festival (Mardi Gras):", fourth_festival_location)
  • Purpose: This accesses and prints the location of the 4th festival in the dictionary (which is 'Mardi Gras').

  • Step-by-step explanation:

    • festival_locations_dict.values() returns a list of the locations (values) from the dictionary.

    • list(festival_locations_dict.values())[3] converts the dictionary values to a list and accesses the value at index 3 (which is the location for the 4th festival: 'Mardi Gras').

    • The location ('USA') is printed as the location of the 4th festival.

Updating the Location of the 6th Festival (La Tomatina)

festival_locations_dict['La Tomatina'] = 'Spain (updated)'
print("\nUpdated location of the 6th festival (La Tomatina):", festival_locations_dict['La Tomatina'])
  • Purpose: This updates the location of the 'La Tomatina' festival to 'Spain (updated)'.

  • Step-by-step explanation:

    • festival_locations_dict['La Tomatina'] = 'Spain (updated)' updates the value associated with the key 'La Tomatina' in the dictionary.

    • After updating the location, the new value ('Spain (updated)') is printed.

Deleting the 2nd Festival (Carnival) from the Dictionary

del festival_locations_dict['Carnival']
print("\nDictionary after deleting the 2nd festival (Carnival):")
print(festival_locations_dict)
  • Purpose: This deletes the key-value pair for the 'Carnival' festival from the dictionary.

  • Step-by-step explanation:

    • del festival_locations_dict['Carnival'] removes the entry for 'Carnival' from the dictionary.

    • After deletion, the updated dictionary (without 'Carnival') is printed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(festival_locations_dict.keys())[-1]
last_value = festival_locations_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This retrieves and prints the last key-value pair in the dictionary after the deletion of 'Carnival'.

  • Step-by-step explanation:

    • festival_locations_dict.keys() returns a list of all the keys (festival names) in the dictionary.

    • list(festival_locations_dict.keys())[-1] converts the dictionary keys to a list and accesses the last key.

    • festival_locations_dict[last_key] retrieves the value (location) corresponding to the last key.

    • The last festival and its location are printed as the last key-value pair in the dictionary.

24.flower_meanings_dict.py

Creating the Dictionary of Flowers and Their Symbolic Meanings

pythonCopy codeflower_meanings_dict = {
    'Rose': 'Love and passion',
    'Lily': 'Purity and refined beauty',
    'Tulip': 'Perfect love',
    'Orchid': 'Luxury and strength',
    'Daisy': 'Innocence and purity',
    'Sunflower': 'Adoration and loyalty',
    'Violet': 'Modesty and faithfulness',
    'Chrysanthemum': 'Optimism and joy'
}
  • Purpose: This creates a dictionary called flower_meanings_dict where the keys are flower names, and the values are their symbolic meanings.

  • The dictionary contains 8 flowers, for example:

    • 'Rose' symbolizes 'Love and passion'.

    • 'Lily' symbolizes 'Purity and refined beauty', and so on.

Printing the Entire Dictionary

print("The entire dictionary:", flower_meanings_dict)
  • Purpose: This line prints the entire dictionary, displaying each flower and its associated meaning.

Accessing and Printing the Meaning of the 5th Flower (Daisy)

fifth_flower_meaning = list(flower_meanings_dict.values())[4]  # Index 4 for the 5th item
print("\nThe meaning of the 5th flower (Daisy):", fifth_flower_meaning)
  • Purpose: This retrieves and prints the meaning of the 5th flower in the dictionary (which is 'Daisy').

  • Step-by-step explanation:

    • flower_meanings_dict.values() returns a list of all the meanings (values) in the dictionary.

    • list(flower_meanings_dict.values())[4] converts the values to a list and accesses the value at index 4 (the meaning of 'Daisy', which is 'Innocence and purity').

    • The meaning ('Innocence and purity') is printed as the meaning of the 5th flower.

Updating the Meaning of the 7th Flower (Violet)

flower_meanings_dict['Violet'] = 'Humility and spirituality'  # Updating the meaning of Violet
print("\nUpdated meaning of the 7th flower (Violet):", flower_meanings_dict['Violet'])
  • Purpose: This updates the symbolic meaning of the 'Violet' flower to 'Humility and spirituality'.

  • Step-by-step explanation:

    • flower_meanings_dict['Violet'] = 'Humility and spirituality' updates the value associated with the key 'Violet'.

    • After the update, the new meaning ('Humility and spirituality') is printed.

Deleting the 6th Flower (Sunflower) from the Dictionary

del flower_meanings_dict['Sunflower']
print("\nDictionary after deleting the 6th flower (Sunflower):", flower_meanings_dict)
  • Purpose: This deletes the key-value pair for the 'Sunflower' flower from the dictionary.

  • Step-by-step explanation:

    • del flower_meanings_dict['Sunflower'] removes the entry for 'Sunflower' from the dictionary.

    • After deletion, the updated dictionary (without 'Sunflower') is printed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(flower_meanings_dict.keys())[-1]
last_value = flower_meanings_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This retrieves and prints the last key-value pair in the dictionary after the deletion of 'Sunflower'.

  • Step-by-step explanation:

    • flower_meanings_dict.keys() returns a list of all the keys (flower names) in the dictionary.

    • list(flower_meanings_dict.keys())[-1] converts the dictionary keys to a list and accesses the last key.

    • flower_meanings_dict[last_key] retrieves the value (symbolic meaning) corresponding to the last key.

    • The last flower and its meaning are printed as the last key-value pair in the dictionary.

25.food_recipes_dict.py

Creating the Dictionary of Foods and Their Recipes

food_recipes_dict = {
    'Pizza': 'Dough, tomato sauce, cheese, toppings of your choice',
    'Pasta': 'Pasta, olive oil, garlic, tomatoes, basil, parmesan',
    'Burger': 'Beef patty, lettuce, tomato, cheese, burger bun',
    'Sushi': 'Rice, nori (seaweed), fish, wasabi, soy sauce',
    'Tacos': 'Taco shells, ground beef, lettuce, cheese, salsa, sour cream',
    'Salad': 'Lettuce, tomatoes, cucumber, olive oil, vinegar',
    'Fried Rice': 'Rice, eggs, soy sauce, peas, carrots, onions',
    'Pancakes': 'Flour, eggs, milk, sugar, butter, syrup'
}
  • Purpose: This creates a dictionary called food_recipes_dict where:

    • The keys are food names (e.g., 'Pizza', 'Pasta').

    • The values are the recipes for each food item (e.g., 'Dough, tomato sauce, cheese, toppings of your choice').

Printing the Entire Dictionary

print("The entire dictionary:")
print(food_recipes_dict)
  • Purpose: This line prints the entire dictionary, displaying all the food names and their respective recipes.

Accessing and Printing the Recipe of the 5th Food (Tacos)

fifth_food_recipe = list(food_recipes_dict.values())[4]  # Index 4 for the 5th food
print("\nRecipe of the 5th food (Tacos):", fifth_food_recipe)
  • Purpose: This retrieves and prints the recipe of the 5th food item in the dictionary (which is 'Tacos').

  • Step-by-step explanation:

    • food_recipes_dict.values() returns a list of all the recipes (values) in the dictionary.

    • list(food_recipes_dict.values())[4] converts the values to a list and accesses the recipe at index 4 (which corresponds to the recipe for 'Tacos').

    • The recipe ('Taco shells, ground beef, lettuce, cheese, salsa, sour cream') is printed as the recipe for the 5th food.

Updating the Recipe of the 3rd Food (Burger)

food_recipes_dict['Burger'] = 'Beef patty, lettuce, tomato, bacon, cheese, burger bun'
print("\nUpdated recipe of the 3rd food (Burger):", food_recipes_dict['Burger'])
  • Purpose: This updates the recipe of the 'Burger' food item.

  • Step-by-step explanation:

    • food_recipes_dict['Burger'] = 'Beef patty, lettuce, tomato, bacon, cheese, burger bun' updates the recipe for 'Burger' to include bacon.

    • After updating, the new recipe ('Beef patty, lettuce, tomato, bacon, cheese, burger bun') is printed.

Deleting the 7th Food (Fried Rice) from the Dictionary

del food_recipes_dict['Fried Rice']
print("\nDictionary after deleting the 7th food (Fried Rice):")
print(food_recipes_dict)
  • Purpose: This deletes the 'Fried Rice' entry from the dictionary.

  • Step-by-step explanation:

    • del food_recipes_dict['Fried Rice'] removes the key-value pair for 'Fried Rice' from the dictionary.

    • After deletion, the updated dictionary (without 'Fried Rice') is printed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(food_recipes_dict.keys())[-1]
last_value = food_recipes_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This retrieves and prints the last key-value pair in the dictionary after 'Fried Rice' has been deleted.

  • Step-by-step explanation:

    • food_recipes_dict.keys() returns a list of all the keys (food names) in the dictionary.

    • list(food_recipes_dict.keys())[-1] converts the dictionary keys to a list and accesses the last key.

    • food_recipes_dict[last_key] retrieves the value (recipe) corresponding to the last key.

    • The last food and its recipe are printed as the last key-value pair in the dictionary.

26.fruit_colors_dict.py

Creating the Dictionary of Fruits and Their Corresponding Colors

fruit_colors_dict = {
    'Apple': 'Red',
    'Banana': 'Yellow',
    'Orange': 'Orange',
    'Grapes': 'Purple',
    'Blueberry': 'Blue',
    'Strawberry': 'Red',
    'Pineapple': 'Yellow',
    'Watermelon': 'Green'
}
  • Purpose: This creates a dictionary named fruit_colors_dict where:

    • The keys represent different fruit names (e.g., 'Apple', 'Banana').

    • The values represent the corresponding colors of the fruits (e.g., 'Red', 'Yellow').

Printing the Entire Dictionary

print("The entire dictionary:", fruit_colors_dict)
  • Purpose: This line prints the entire dictionary to the console. It shows all the fruit names and their respective colors in the dictionary.

Accessing and Printing the Color of the 6th Fruit (Strawberry)

sixth_fruit_color = list(fruit_colors_dict.values())[5]  # Index 5 for the 6th item
print("\nThe color of the 6th fruit (Strawberry):", sixth_fruit_color)
  • Purpose: This retrieves and prints the color of the 6th fruit (which is 'Strawberry').

  • Step-by-step explanation:

    • fruit_colors_dict.values() retrieves a view object of all the colors (values) in the dictionary.

    • list(fruit_colors_dict.values())[5] converts this view to a list and accesses the color at index 5 (the color for 'Strawberry').

    • The result ('Red') is printed as the color of the 6th fruit.

Updating the Color of the 4th Fruit (Grapes)

fruit_colors_dict['Grapes'] = 'Green'
print("\nUpdated color of the 4th fruit (Grapes):", fruit_colors_dict['Grapes'])
  • Purpose: This updates the color of the 4th fruit (which is 'Grapes') to 'Green'.

  • Step-by-step explanation:

    • fruit_colors_dict['Grapes'] = 'Green' changes the color value for the key 'Grapes' from 'Purple' to 'Green'.

    • The updated color ('Green') for 'Grapes' is then printed.

Deleting the 7th Fruit (Pineapple) from the Dictionary

del fruit_colors_dict['Pineapple']
print("\nDictionary after deleting the 7th fruit (Pineapple):", fruit_colors_dict)
  • Purpose: This deletes the entry for 'Pineapple' from the dictionary.

  • Step-by-step explanation:

    • del fruit_colors_dict['Pineapple'] removes the key-value pair for 'Pineapple' from the dictionary.

    • The updated dictionary, with 'Pineapple' removed, is then printed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(fruit_colors_dict.keys())[-1]
last_value = fruit_colors_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This retrieves and prints the last key-value pair in the dictionary after the deletion of 'Pineapple'.

  • Step-by-step explanation:

    • fruit_colors_dict.keys() returns a view object containing all the keys (fruit names) in the dictionary.

    • list(fruit_colors_dict.keys())[-1] converts this view to a list and accesses the last key.

    • fruit_colors_dict[last_key] retrieves the value (color) corresponding to the last key.

    • The last key-value pair (e.g., 'Watermelon': 'Green') is printed.

27.historical_events_dict.py

Creating the Dictionary of Historical Events and Their Years

historical_events_dict = {
    'The Declaration of Independence': 1776,
    'The French Revolution': 1789,
    'World War I Begins': 1914,
    'World War II Begins': 1939,
    'The Moon Landing': 1969,
    'Fall of the Berlin Wall': 1989,
    'The September 11 Attacks': 2001,
    'The End of Apartheid in South Africa': 1994
}
  • Purpose: This creates a dictionary called historical_events_dict, where:

    • The keys represent historical events (e.g., 'The Declaration of Independence').

    • The values represent the year when these events occurred (e.g., 1776 for 'The Declaration of Independence').

Printing the Entire Dictionary

print("The entire dictionary:", historical_events_dict)
  • Purpose: This line prints the entire dictionary to the console. It displays all the events and their corresponding years in the dictionary.

Accessing and Printing the Year of the 2nd Event (The French Revolution)

second_event_year = list(historical_events_dict.values())[1]  # Index 1 for the 2nd event
print("\nThe year of the 2nd event (The French Revolution):", second_event_year)
  • Purpose: This retrieves and prints the year of the 2nd event in the dictionary, which is 'The French Revolution'.

  • Step-by-step explanation:

    • historical_events_dict.values() gives a view of all the years (values) in the dictionary.

    • list(historical_events_dict.values())[1] converts this view to a list and accesses the value at index 1 (the year for 'The French Revolution').

    • The result (1789) is printed as the year of the 2nd event.

Updating the Year of the 7th Event (The September 11 Attacks)

historical_events_dict['The September 11 Attacks'] = 2002  # Updating the year
print("\nUpdated year of the 7th event (The September 11 Attacks):", historical_events_dict['The September 11 Attacks'])
  • Purpose: This updates the year of the 7th event (which is 'The September 11 Attacks') to 2002.

  • Step-by-step explanation:

    • historical_events_dict['The September 11 Attacks'] = 2002 changes the value associated with the key 'The September 11 Attacks' from 2001 to 2002.

    • The updated year (2002) for 'The September 11 Attacks' is then printed.

Deleting the 5th Event (The Moon Landing) from the Dictionary

del historical_events_dict['The Moon Landing']
print("\nDictionary after deleting the 5th event (The Moon Landing):", historical_events_dict)
  • Purpose: This deletes the entry for 'The Moon Landing' from the dictionary.

  • Step-by-step explanation:

    • del historical_events_dict['The Moon Landing'] removes the key-value pair for 'The Moon Landing' from the dictionary.

    • The updated dictionary, with 'The Moon Landing' removed, is then printed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(historical_events_dict.keys())[-1]
last_value = historical_events_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This retrieves and prints the last key-value pair in the dictionary after the deletion of 'The Moon Landing'.

  • Step-by-step explanation:

    • historical_events_dict.keys() returns a view object containing all the keys (event names) in the dictionary.

    • list(historical_events_dict.keys())[-1] converts this view to a list and accesses the last key.

    • historical_events_dict[last_key] retrieves the value (year) corresponding to the last key.

    • The last key-value pair (e.g., 'The End of Apartheid in South Africa': 1994) is printed.

28.holiday_dates_dict.py

Creating the Dictionary of Holidays and Their Corresponding Dates

holiday_dates_dict = {
    'New Year\'s Day': 'January 1',
    'Valentine\'s Day': 'February 14',
    'Easter': 'April 9, 2023',
    'Independence Day': 'July 4',
    'Halloween': 'October 31',
    'Thanksgiving': 'November 23, 2023',
    'Christmas': 'December 25',
    'Labor Day': 'First Monday in September',
    'Memorial Day': 'Last Monday in May',
    'Veterans Day': 'November 11'
}
  • Purpose: This creates a dictionary named holiday_dates_dict where:

    • The keys are holiday names (e.g., 'New Year's Day', 'Valentine's Day').

    • The values are the corresponding dates of those holidays (e.g., 'January 1', 'February 14').

Printing the Entire Dictionary

print("The entire dictionary:", holiday_dates_dict)
  • Purpose: This line prints the entire holiday_dates_dict dictionary to the console. It will display all the holidays along with their corresponding dates.

Accessing and Printing the Date of the 4th Holiday (Independence Day)

fourth_holiday_date = list(holiday_dates_dict.values())[3]  # Index 3 for the 4th item
print("\nThe date of the 4th holiday (Independence Day):", fourth_holiday_date)
  • Purpose: This retrieves and prints the date of the 4th holiday in the dictionary, which is 'Independence Day'.

  • Step-by-step explanation:

    • holiday_dates_dict.values() returns a view object of all the holiday dates.

    • list(holiday_dates_dict.values())[3] converts the view to a list and accesses the date at index 3, which corresponds to 'Independence Day' (i.e., 'July 4').

    • The result is printed: 'July 4'.

Updating the Date of the 9th Holiday (Memorial Day)

holiday_dates_dict['Memorial Day'] = 'May 29, 2023'  # Updating the date of Memorial Day
print("\nUpdated date of the 9th holiday (Memorial Day):", holiday_dates_dict['Memorial Day'])
  • Purpose: This updates the date of the 9th holiday, 'Memorial Day', to 'May 29, 2023'.

  • Step-by-step explanation:

    • holiday_dates_dict['Memorial Day'] = 'May 29, 2023' changes the value associated with the key 'Memorial Day' from 'Last Monday in May' to 'May 29, 2023'.

    • The updated date ('May 29, 2023') for 'Memorial Day' is printed.

Deleting the 2nd Holiday (Valentine's Day) from the Dictionary

del holiday_dates_dict['Valentine\'s Day']
print("\nDictionary after deleting the 2nd holiday (Valentine's Day):", holiday_dates_dict)
  • Purpose: This deletes the entry for 'Valentine's Day' from the dictionary.

  • Step-by-step explanation:

    • del holiday_dates_dict['Valentine\'s Day'] removes the key-value pair for 'Valentine's Day' from the dictionary.

    • The updated dictionary, without 'Valentine's Day', is printed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(holiday_dates_dict.keys())[-1]
last_value = holiday_dates_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This retrieves and prints the last key-value pair in the dictionary after the deletion of 'Valentine's Day'.

  • Step-by-step explanation:

    • holiday_dates_dict.keys() returns a view object of all the keys (holiday names).

    • list(holiday_dates_dict.keys())[-1] converts this view to a list and accesses the last key.

    • holiday_dates_dict[last_key] retrieves the corresponding date for that key.

    • The last key-value pair is printed (for example, 'Veterans Day': 'November 11').

29.job_salaries_dict.py

Creating the Dictionary of Jobs and Their Salaries

job_salaries_dict = {
    'Software Engineer': 100000,
    'Data Scientist': 95000,
    'Product Manager': 120000,
    'Graphic Designer': 55000,
    'Accountant': 65000,
    'Teacher': 45000,
    'Nurse': 75000,
    'Web Developer': 85000,
    'Project Manager': 105000,
    'Chef': 40000
}
  • Purpose: This creates a dictionary job_salaries_dict, where:

    • The keys are job titles (e.g., 'Software Engineer', 'Data Scientist', 'Product Manager').

    • The values are their corresponding average salaries (e.g., 100000, 95000, 120000).

Printing the Entire Dictionary

print("The entire dictionary:", job_salaries_dict)
  • Purpose: This prints the entire job_salaries_dict dictionary, showing all job titles and their corresponding salaries.

Accessing and Printing the Salary of the 3rd Job (Product Manager)

third_job_salary = list(job_salaries_dict.values())[2]  # Index 2 for the 3rd job
print("\nSalary of the 3rd job (Product Manager):", third_job_salary)
  • Purpose: This retrieves the salary for the 3rd job (index 2 in Python, since indices start at 0), which is 'Product Manager'.

  • Step-by-step explanation:

    • job_salaries_dict.values() returns a view of all the salaries in the dictionary.

    • list(job_salaries_dict.values())[2] converts the view into a list and accesses the value at index 2, which corresponds to 'Product Manager' with a salary of 120000.

    • The result is printed: 'Salary of the 3rd job (Product Manager): 120000'.

Updating the Salary of the 7th Job (Nurse)

job_salaries_dict['Nurse'] = 80000
print("\nUpdated salary of the 7th job (Nurse):", job_salaries_dict['Nurse'])
  • Purpose: This updates the salary for the 'Nurse' job to 80000.

  • Step-by-step explanation:

    • job_salaries_dict['Nurse'] = 80000 updates the salary of 'Nurse' from 75000 to 80000.

    • The updated salary (80000) is printed.

Deleting the 9th Job (Project Manager) from the Dictionary

del job_salaries_dict['Project Manager']
print("\nDictionary after deleting the 9th job (Project Manager):", job_salaries_dict)
  • Purpose: This deletes the entry for 'Project Manager' from the dictionary.

  • Step-by-step explanation:

    • del job_salaries_dict['Project Manager'] removes the 'Project Manager' key-value pair from the dictionary.

    • The updated dictionary, without the 'Project Manager', is printed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(job_salaries_dict.keys())[-1]
last_value = job_salaries_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This retrieves and prints the last key-value pair in the dictionary after the deletion of 'Project Manager'.

  • Step-by-step explanation:

    • job_salaries_dict.keys() returns a view of all the job titles.

    • list(job_salaries_dict.keys())[-1] converts the view to a list and accesses the last key.

    • job_salaries_dict[last_key] retrieves the corresponding salary for that job title.

    • The last key-value pair is printed (for example, 'Chef': 40000).

30.movie_directors_dict.py

Creating the Dictionary of Movies and Directors

movie_directors_dict = {
    'Inception': 'Christopher Nolan',
    'The Dark Knight': 'Christopher Nolan',
    'Interstellar': 'Christopher Nolan',
    'The Matrix': 'Wachowskis',
    'Pulp Fiction': 'Quentin Tarantino',
    'The Shawshank Redemption': 'Frank Darabont',
    'The Godfather': 'Francis Ford Coppola',
    'Fight Club': 'David Fincher',
    'Forrest Gump': 'Robert Zemeckis',
    'The Lion King': 'Roger Allers, Rob Minkoff'
}
  • Purpose: This dictionary movie_directors_dict maps movie titles to their directors.

  • Example: 'Inception' maps to 'Christopher Nolan', 'Pulp Fiction' maps to 'Quentin Tarantino', and so on.

Printing the Entire Dictionary

print("The entire dictionary:", movie_directors_dict)
  • Purpose: This prints the entire movie_directors_dict, showing all the movie titles and their corresponding directors.

Accessing and Printing the Director of the 5th Movie (Pulp Fiction)

fifth_movie_director = list(movie_directors_dict.values())[4]  # Index 4 for the 5th item
print("\nThe director of the 5th movie (Pulp Fiction):", fifth_movie_director)
  • Purpose: This retrieves the director of the 5th movie in the list (index 4, because indices start from 0).

  • Explanation:

    • movie_directors_dict.values() returns a view of all the directors in the dictionary.

    • list(movie_directors_dict.values())[4] converts the view into a list and retrieves the director for the 5th movie, which is 'Pulp Fiction'. The director is 'Quentin Tarantino'.

    • The result is printed: 'The director of the 5th movie (Pulp Fiction): Quentin Tarantino'.

Updating the Director of the 9th Movie (Forrest Gump)

movie_directors_dict['Forrest Gump'] = 'Updated Director'
print("\nUpdated director of the 9th movie (Forrest Gump):", movie_directors_dict['Forrest Gump'])
  • Purpose: This updates the director of 'Forrest Gump' from 'Robert Zemeckis' to 'Updated Director'.

  • Explanation:

    • movie_directors_dict['Forrest Gump'] = 'Updated Director' changes the value associated with the key 'Forrest Gump'.

    • The updated director is printed: 'Updated director of the 9th movie (Forrest Gump): Updated Director'.

Deleting the 7th Movie (The Godfather) from the Dictionary

del movie_directors_dict['The Godfather']
print("\nDictionary after deleting the 7th movie (The Godfather):", movie_directors_dict)
  • Purpose: This deletes the entry for 'The Godfather' from the dictionary.

  • Explanation:

    • del movie_directors_dict['The Godfather'] removes the key-value pair for 'The Godfather' from the dictionary.

    • The updated dictionary is printed, which no longer contains 'The Godfather'.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(movie_directors_dict.keys())[-1]
last_value = movie_directors_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This prints the last key-value pair in the updated dictionary.

  • Explanation:

    • movie_directors_dict.keys() returns a view of all the movie titles.

    • list(movie_directors_dict.keys())[-1] converts the view to a list and accesses the last key (the last movie in the list).

    • movie_directors_dict[last_key] retrieves the corresponding director for that movie.

    • The last key-value pair is printed.

31.movie_genres_dict.py

Creating the Dictionary of Movie Genres and Example Movies

movie_genres_dict = {
    'Action': 'Mad Max: Fury Road',
    'Comedy': 'The Hangover',
    'Drama': 'The Shawshank Redemption',
    'Horror': 'A Nightmare on Elm Street',
    'Romance': 'The Notebook',
    'Sci-Fi': 'Inception',
    'Animation': 'Toy Story',
    'Thriller': 'Se7en'
}
  • Purpose: This dictionary, movie_genres_dict, maps different movie genres to an example movie that represents that genre.

  • Example: 'Action' is paired with 'Mad Max: Fury Road', 'Comedy' is paired with 'The Hangover', etc.

Printing the Entire Dictionary

print("The entire dictionary:", movie_genres_dict)
  • Purpose: This prints the entire movie_genres_dict, showing all the movie genres and their corresponding example movies.

Accessing and Printing the Example Movie of the 3rd Genre (Drama)

third_genre_movie = list(movie_genres_dict.values())[2]  # Index 2 for the 3rd item
print("\nThe example movie of the 3rd genre (Drama):", third_genre_movie)
  • Purpose: This retrieves and prints the example movie for the 3rd genre (index 2, since Python uses 0-based indexing).

  • Explanation:

    • movie_genres_dict.values() returns all the example movies.

    • list(movie_genres_dict.values())[2] converts the view of movies to a list and accesses the movie at index 2, which is 'The Shawshank Redemption' (for the 'Drama' genre).

    • The result is printed: 'The example movie of the 3rd genre (Drama): The Shawshank Redemption'.

Updating the Example Movie of the 5th Genre (Romance)

movie_genres_dict['Romance'] = 'Pride and Prejudice'  # Updating the example movie of Romance genre
print("\nUpdated example movie of the 5th genre (Romance):", movie_genres_dict['Romance'])
  • Purpose: This updates the example movie for the 'Romance' genre from 'The Notebook' to 'Pride and Prejudice'.

  • Explanation:

    • movie_genres_dict['Romance'] = 'Pride and Prejudice' changes the value associated with the 'Romance' key.

    • The updated movie is printed: 'Updated example movie of the 5th genre (Romance): Pride and Prejudice'.

Deleting the 7th Genre (Animation) from the Dictionary

del movie_genres_dict['Animation']
print("\nDictionary after deleting the 7th genre (Animation):", movie_genres_dict)
  • Purpose: This deletes the entry for 'Animation' from the dictionary.

  • Explanation:

    • del movie_genres_dict['Animation'] removes the key-value pair for the 'Animation' genre.

    • The updated dictionary is printed, showing that the 'Animation' entry has been removed.

Printing the Last Key-Value Pair in the Dictionary

last_key = list(movie_genres_dict.keys())[-1]
last_value = movie_genres_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This prints the last key-value pair in the updated dictionary.

  • Explanation:

    • movie_genres_dict.keys() returns a view of all the genres.

    • list(movie_genres_dict.keys())[-1] converts the view to a list and accesses the last genre (the last key in the dictionary).

    • movie_genres_dict[last_key] retrieves the corresponding example movie for that genre.

    • The last key-value pair is printed.

32.music_albums_dict.py

Creating the Dictionary of Music Albums and Release Years:

music_albums_dict = {
    'Future Nostalgia': 2020,
    'Lover': 2019,
    'After Hours': 2020,
    'Folklore': 2020,
    'Scorpion': 2018,
    'Fine Line': 2019,
    'What’s Your Pleasure?': 2020,
    'Chromatica': 2020,
    'Positions': 2020,
    'Fearless (Taylor’s Version)': 2021
}
  • Purpose: This dictionary, music_albums_dict, contains album names as keys and their release years as values.

  • Example: 'Future Nostalgia' by Dua Lipa was released in 2020, and 'Scorpion' by Drake was released in 2018.

    Printing the Entire Dictionary:

print("The entire dictionary:", music_albums_dict)
  • Purpose: This prints the entire dictionary, showing the album names and their corresponding release years.

    Accessing and Printing the Release Year of the 3rd Album (After Hours):

third_album_year = list(music_albums_dict.values())[2]  # Index 2 for the 3rd album
print("\nThe release year of the 3rd album (After Hours):", third_album_year)
  • Purpose: This accesses and prints the release year of the 3rd album, 'After Hours' by The Weeknd.

  • Explanation:

    • list(music_albums_dict.values()) converts the dictionary values (release years) to a list.

    • The third album is at index 2 (since Python uses 0-based indexing).

    • 'After Hours' was released in 2020.

Updating the Release Year of the 8th Album (Chromatica):

music_albums_dict['Chromatica'] = 2021  # Updating the release year
print("\nUpdated release year of the 8th album (Chromatica):", music_albums_dict['Chromatica'])
  • Purpose: This updates the release year for 'Chromatica' by Lady Gaga from 2020 to 2021.

  • Explanation:

    • music_albums_dict['Chromatica'] = 2021 updates the value for the 'Chromatica' key.

    • The updated release year is printed: 'Updated release year of the 8th album (Chromatica): 2021'.

Deleting the 5th Album (Scorpion) from the Dictionary:

del music_albums_dict['Scorpion']
print("\nDictionary after deleting the 5th album (Scorpion):", music_albums_dict)
  • Purpose: This deletes the album 'Scorpion' from the dictionary.

  • Explanation:

    • del music_albums_dict['Scorpion'] removes the 'Scorpion' key-value pair from the dictionary.

    • The updated dictionary is printed, showing that 'Scorpion' is no longer included.

Printing the Last Key-Value Pair in the Dictionary:

last_key = list(music_albums_dict.keys())[-1]
last_value = music_albums_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This prints the last key-value pair (album and release year) in the updated dictionary.

  • Explanation:

    • list(music_albums_dict.keys())[-1] gets the last key (album name) in the dictionary.

    • music_albums_dict[last_key] retrieves the corresponding release year.

    • The last key-value pair is printed.

33.phone_models_dict.py

Creating the Dictionary of Phone Models and Manufacturers:

phone_models_dict = {
    'iPhone 15': 'Apple',
    'Galaxy S23': 'Samsung',
    'Pixel 8': 'Google',
    'OnePlus 11': 'OnePlus',
    'Xperia 1 IV': 'Sony',
    'Moto G Power': 'Motorola',
    'Redmi Note 12': 'Xiaomi',
    'Galaxy Z Fold 5': 'Samsung',
    'Nokia G400': 'Nokia',
    'Huawei P60': 'Huawei'
}
  • Purpose: This dictionary, phone_models_dict, contains phone model names as keys and their manufacturers as values.

  • Example: 'iPhone 15' is manufactured by 'Apple', and 'Galaxy S23' is made by 'Samsung'.

    Printing the Entire Dictionary:

print("The entire dictionary:", phone_models_dict)
  • Purpose: This prints the entire dictionary, showing the phone models and their corresponding manufacturers.

    Accessing and Printing the Manufacturer of the 2nd Phone Model (Galaxy S23):

second_phone_manufacturer = list(phone_models_dict.values())[1]  # Index 1 for the 2nd phone model
print("\nThe manufacturer of the 2nd phone model (Galaxy S23):", second_phone_manufacturer)
  • Purpose: This accesses and prints the manufacturer of the 2nd phone model, 'Galaxy S23' by Samsung.

  • Explanation:

    • list(phone_models_dict.values()) converts the dictionary values (manufacturers) to a list.

    • The second phone model is at index 1 (since Python uses 0-based indexing).

    • 'Galaxy S23' is manufactured by 'Samsung'.

Updating the Manufacturer of the 8th Phone Model (Galaxy Z Fold 5):

phone_models_dict['Galaxy Z Fold 5'] = 'Samsung Electronics'  # Updating the manufacturer
print("\nUpdated manufacturer of the 8th phone model (Galaxy Z Fold 5):", phone_models_dict['Galaxy Z Fold 5'])
  • Purpose: This updates the manufacturer for 'Galaxy Z Fold 5' from 'Samsung' to 'Samsung Electronics'.

  • Explanation:

    • phone_models_dict['Galaxy Z Fold 5'] = 'Samsung Electronics' updates the manufacturer value.

    • The updated manufacturer is printed: 'Updated manufacturer of the 8th phone model (Galaxy Z Fold 5): Samsung Electronics'.

Deleting the 6th Phone Model (Moto G Power) from the Dictionary:

del phone_models_dict['Moto G Power']
print("\nDictionary after deleting the 6th phone model (Moto G Power):", phone_models_dict)
  • Purpose: This deletes the phone model 'Moto G Power' from the dictionary.

  • Explanation:

    • del phone_models_dict['Moto G Power'] removes the 'Moto G Power' key-value pair from the dictionary.

    • The updated dictionary is printed, showing that 'Moto G Power' is no longer included.

Printing the Last Key-Value Pair in the Dictionary:

last_key = list(phone_models_dict.keys())[-1]
last_value = phone_models_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • Purpose: This prints the last key-value pair (phone model and manufacturer) in the updated dictionary.

  • Explanation:

    • list(phone_models_dict.keys())[-1] gets the last key (phone model) in the dictionary.

    • phone_models_dict[last_key] retrieves the corresponding manufacturer.

    • The last key-value pair is printed.

34.planet_distances_dict.py

Creating the Dictionary of Planet Distances:

planet_distances_dict = {
    'Mercury': 57.9,
    'Venus': 108.2,
    'Earth': 149.6,
    'Mars': 227.9,
    'Jupiter': 778.3,
    'Saturn': 1427.0,
    'Uranus': 2871.0,
    'Neptune': 4497.1
}
  • This dictionary contains the names of the 8 planets as keys and their corresponding distances from the Sun (in million kilometers) as values.

    Printing the Entire Dictionary:

print("The entire dictionary:", planet_distances_dict)
  • This prints the entire planet_distances_dict, showing the planets and their distances from the Sun.

    Accessing and Printing the Distance of the 3rd Planet (Earth):

third_planet_distance = list(planet_distances_dict.values())[2]  # Index 2 for the 3rd planet
print("\nThe distance of the 3rd planet (Earth):", third_planet_distance, "million kilometers")
  • The 3rd planet, Earth, is accessed by converting the dictionary values to a list and selecting the value at index 2 (because Python uses 0-based indexing).

  • The distance of Earth from the Sun is printed.

    Updating the Distance of the 5th Planet (Jupiter):

planet_distances_dict['Jupiter'] = 800.0  # Updating the distance of Jupiter
print("\nUpdated distance of the 5th planet (Jupiter):", planet_distances_dict['Jupiter'], "million kilometers")
  • This updates the distance for Jupiter from 778.3 million kilometers to 800.0 million kilometers.

  • The updated distance is printed.

    Deleting the 7th Planet (Uranus) from the Dictionary:

del planet_distances_dict['Uranus']
print("\nDictionary after deleting the 7th planet (Uranus):", planet_distances_dict)
  • The planet Uranus is removed from the dictionary using the del statement.

  • The updated dictionary, without Uranus, is printed.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(planet_distances_dict.keys())[-1]
last_value = planet_distances_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last planet in the dictionary is accessed and printed.

  • This is done by converting the dictionary keys to a list and selecting the last key ([-1] index).

  • The corresponding value (distance from the Sun) is also printed.

35.plant_types_dict.py

Creating the Dictionary of Plants and Their Types:

plant_types_dict = {
    'Rose': 'Shrub',
    'Oak': 'Tree',
    'Basil': 'Herb',
    'Cactus': 'Succulent',
    'Tulip': 'Flowering Plant',
    'Fern': 'Fern',
    'Lavender': 'Herb',
    'Pine': 'Tree'
}
  • The dictionary plant_types_dict maps plant names to their corresponding types. For example, Rose is mapped to Shrub, Oak to Tree, and so on.

    Printing the Entire Dictionary:

print("The entire dictionary:", plant_types_dict)
  • This prints the entire dictionary, showing the plant names as keys and their types as values.

    Accessing and Printing the Type of the 5th Plant (Tulip):

fifth_plant_type = list(plant_types_dict.values())[4]  # Index 4 for the 5th plant
print("\nThe type of the 5th plant (Tulip):", fifth_plant_type)
  • The type of the 5th plant (Tulip) is accessed by converting the dictionary values to a list and selecting the value at index 4 (since Python uses 0-based indexing). The type of the Tulip is printed as Flowering Plant.

    Updating the Type of the 2nd Plant (Oak):

plant_types_dict['Oak'] = 'Deciduous Tree'  # Updating the type
print("\nUpdated type of the 2nd plant (Oak):", plant_types_dict['Oak'])
  • The type of Oak (the 2nd plant) is updated from Tree to Deciduous Tree.

  • The updated type of the Oak is printed.

    Deleting the 6th Plant (Fern) from the Dictionary:

del plant_types_dict['Fern']
print("\nDictionary after deleting the 6th plant (Fern):", plant_types_dict)
  • The 6th plant, Fern, is removed from the dictionary using the del statement.

  • The updated dictionary, after removing Fern, is printed.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(plant_types_dict.keys())[-1]
last_value = plant_types_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last plant and its type are accessed by converting the dictionary keys to a list and selecting the last key ([-1] index).

  • The corresponding value (the plant's type) is then printed.

36.product_prices_dict.py

Creating the Dictionary of Products and Prices:

product_prices_dict = {
    'Laptop': 999.99,
    'Smartphone': 799.99,
    'Headphones': 199.99,
    'Keyboard': 49.99,
    'Mouse': 29.99,
    'Monitor': 159.99,
    'USB Drive': 19.99,
    'Webcam': 79.99,
    'Smartwatch': 249.99,
    'Speaker': 89.99
}
  • The dictionary product_prices_dict maps product names to their prices. For example, Laptop is mapped to 999.99, Smartphone to 799.99, and so on.

    Printing the Entire Dictionary:

print("The entire dictionary:", product_prices_dict)
  • This line prints the entire dictionary, showing all products and their respective prices.

    Accessing and Printing the Price of the 4th Product (Keyboard):

fourth_product_price = list(product_prices_dict.values())[3]  # Index 3 for the 4th product
print("\nThe price of the 4th product (Keyboard):", fourth_product_price)
  • The price of the 4th product (Keyboard) is accessed by converting the dictionary values into a list and selecting the price at index 3 (because of 0-based indexing). The price of the Keyboard is then printed as 49.99.

    Updating the Price of the 9th Product (Smartwatch):

product_prices_dict['Smartwatch'] = 259.99  # Updating the price of Smartwatch
print("\nUpdated price of the 9th product (Smartwatch):", product_prices_dict['Smartwatch'])
  • The price of the 9th product (Smartwatch) is updated from 249.99 to 259.99.

  • The updated price of Smartwatch is printed.

    Deleting the 6th Product (Monitor) from the Dictionary:

del product_prices_dict['Monitor']
print("\nDictionary after deleting the 6th product (Monitor):", product_prices_dict)
  • The Monitor (the 6th product) is deleted from the dictionary using the del statement.

  • The dictionary is printed after deleting the Monitor, showing the remaining products.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(product_prices_dict.keys())[-1]
last_value = product_prices_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last key (product) and its corresponding value (price) are accessed by converting the dictionary keys to a list and selecting the last key ([-1] index).

  • The corresponding price of the last product is printed.

37.programming_languages_dict.py

Creating the Dictionary of Programming Languages and Developers:

programming_languages_dict = {
    'Python': 'Guido van Rossum',
    'Java': 'James Gosling',
    'C++': 'Bjarne Stroustrup',
    'JavaScript': 'Brendan Eich',
    'Ruby': 'Yukihiro Matsumoto',
    'PHP': 'Rasmus Lerdorf',
    'Swift': 'Chris Lattner'
}
  • The dictionary programming_languages_dict is created, where each key is a programming language, and the corresponding value is the name of the developer associated with that language. For example, Python is associated with Guido van Rossum, and Java is associated with James Gosling.

    Printing the Entire Dictionary:

print("The entire dictionary:", programming_languages_dict)
  • This line prints the entire dictionary, showing all programming languages and their developers.

    Accessing and Printing the Developer of the 4th Programming Language (JavaScript):

fourth_language_developer = list(programming_languages_dict.values())[3]  # Index 3 for the 4th item
print("\nThe developer of the 4th programming language (JavaScript):", fourth_language_developer)
  • The developer of the 4th programming language (JavaScript) is accessed by converting the dictionary values into a list and selecting the developer at index 3 (since Python uses 0-based indexing). The developer Brendan Eich is then printed.

    Updating the Developer of the 6th Programming Language (PHP):

programming_languages_dict['PHP'] = 'Andi Gutmans'
print("\nUpdated developer of the 6th programming language (PHP):", programming_languages_dict['PHP'])
  • The developer of the 6th programming language (PHP) is updated from Rasmus Lerdorf to Andi Gutmans.

  • The updated developer of PHP is printed.

    Deleting the 2nd Programming Language (Java) from the Dictionary:

del programming_languages_dict['Java']
print("\nDictionary after deleting the 2nd programming language (Java):", programming_languages_dict)
  • The programming language Java (the 2nd item) is deleted from the dictionary using the del statement.

  • The dictionary is printed again after deleting Java, showing the remaining languages.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(programming_languages_dict.keys())[-1]
last_value = programming_languages_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last key (programming language) and its corresponding value (developer) are accessed by converting the dictionary keys to a list and selecting the last key ([-1] index).

  • The corresponding developer of the last programming language is printed.

38.river_lengths_dict.py

Creating the Dictionary of Rivers and Their Lengths:

river_lengths_dict = {
    'Nile': 6650,
    'Amazon': 6400,
    'Yangtze': 6300,
    'Mississippi': 3730,
    'Ganges': 2525,
    'Danube': 2850
}
  • The dictionary river_lengths_dict is created, where each key is a river name, and the corresponding value is the length of that river in kilometers. For example, the river Nile has a length of 6650 km, and the river Amazon has a length of 6400 km.

    Printing the Entire Dictionary:

print("The entire dictionary:", river_lengths_dict)
  • This line prints the entire dictionary, showing the rivers and their lengths.

    Accessing and Printing the Length of the 2nd River (Amazon):

second_river_length = list(river_lengths_dict.values())[1]  # Index 1 for the 2nd item
print("\nThe length of the 2nd river (Amazon):", second_river_length)
  • The length of the 2nd river (Amazon) is accessed by converting the dictionary values into a list and selecting the value at index 1 (since Python uses 0-based indexing). The length 6400 km is then printed.

    Updating the Length of the 5th River (Ganges):

river_lengths_dict['Ganges'] = 2600  # Updating the length of the Ganges river
print("\nUpdated length of the 5th river (Ganges):", river_lengths_dict['Ganges'])
  • The length of the 5th river (Ganges) is updated from 2525 km to 2600 km.

  • The updated length of the Ganges river is printed.

    Deleting the 4th River (Mississippi) from the Dictionary:

del river_lengths_dict['Mississippi']
print("\nDictionary after deleting the 4th river (Mississippi):", river_lengths_dict)
  • The 4th river (Mississippi) is deleted from the dictionary using the del statement.

  • The dictionary is printed again after deleting the Mississippi river, showing the remaining rivers and their lengths.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(river_lengths_dict.keys())[-1]
last_value = river_lengths_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last key (river) and its corresponding value (length) are accessed by converting the dictionary keys to a list and selecting the last key ([-1] index).

  • The corresponding length of the last river is printed.

39.software_companies_dict.py

Creating the Dictionary of Software Companies and Their Headquarters:

software_companies_dict = {
    'Microsoft': 'Redmond, Washington, USA',
    'Apple': 'Cupertino, California, USA',
    'Google': 'Mountain View, California, USA',
    'Amazon': 'Seattle, Washington, USA',
    'Facebook': 'Menlo Park, California, USA',
    'Adobe': 'San Jose, California, USA',
    'IBM': 'Armonk, New York, USA',
    'Oracle': 'Redwood City, California, USA',
    'SAP': 'Walldorf, Germany',
    'Twitter': 'San Francisco, California, USA'
}
  • The dictionary software_companies_dict is created, where the key is the name of the company, and the corresponding value is the location of its headquarters. For example, the company Microsoft is headquartered in Redmond, Washington, USA.

    Printing the Entire Dictionary:

print("The entire dictionary:", software_companies_dict)
  • This line prints the entire dictionary, displaying the software companies and their respective headquarters.

    Accessing and Printing the Headquarters of the 3rd Company (Google):

third_company_headquarters = list(software_companies_dict.values())[2]  # Index 2 for the 3rd item
print("\nThe headquarters of the 3rd company (Google):", third_company_headquarters)
  • The headquarters of the 3rd company (Google) is accessed by converting the dictionary values into a list and selecting the value at index 2 (since Python uses 0-based indexing).

  • The result is the headquarters location of Google: Mountain View, California, USA.

    Updating the Headquarters of the 8th Company (Oracle):

software_companies_dict['Oracle'] = 'Austin, Texas, USA'  # Updating the headquarters location
print("\nUpdated headquarters of the 8th company (Oracle):", software_companies_dict['Oracle'])
  • The headquarters of the 8th company (Oracle) is updated from Redwood City, California, USA to Austin, Texas, USA.

  • The updated location is printed.

    Deleting the 9th Company (SAP) from the Dictionary:

del software_companies_dict['SAP']
print("\nDictionary after deleting the 9th company (SAP):", software_companies_dict)
  • The 9th company (SAP) is deleted from the dictionary using the del statement.

  • The dictionary is printed again after the deletion, showing the remaining companies and their headquarters.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(software_companies_dict.keys())[-1]
last_value = software_companies_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last company and its headquarters are accessed by converting the dictionary keys to a list and selecting the last key ([-1] index).

  • The corresponding headquarters of the last company is printed.

40.software_versions_dict.py

Creating the Dictionary of Software Programs and Their Versions:

software_versions_dict = {
    'Windows 11': '22H2',
    'macOS Ventura': '13.3',
    'Ubuntu': '23.04',
    'Chrome': '117.0.5938.92',
    'Firefox': '118.0.1',
    'Slack': '4.29.2'
}
  • The dictionary software_versions_dict is created, where each key represents the name of a software program, and its value is the latest version of the software.

    Printing the Entire Dictionary:

print("The entire dictionary:", software_versions_dict)
  • This line prints the entire dictionary, showing the software programs and their corresponding versions.

    Accessing and Printing the Version of the 4th Software (Chrome):

fourth_software_version = list(software_versions_dict.values())[3]  # Index 3 for the 4th software
print("\nThe version of the 4th software (Chrome):", fourth_software_version)
  • The version of the 4th software (Chrome) is accessed by converting the dictionary values into a list and selecting the value at index 3 (since Python uses 0-based indexing).

  • The version of Chrome (117.0.5938.92) is printed.

    Updating the Version of the 2nd Software (macOS Ventura):

software_versions_dict['macOS Ventura'] = '13.4'  # Updating the version
print("\nUpdated version of the 2nd software (macOS Ventura):", software_versions_dict['macOS Ventura'])
  • The version of the 2nd software (macOS Ventura) is updated from 13.3 to 13.4.

  • The updated version is printed.

    Deleting the 5th Software (Firefox) from the Dictionary:

del software_versions_dict['Firefox']
print("\nDictionary after deleting the 5th software (Firefox):", software_versions_dict)
  • The 5th software (Firefox) is deleted from the dictionary using the del statement.

  • The dictionary is printed again after the deletion, showing the remaining software programs and their versions.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(software_versions_dict.keys())[-1]
last_value = software_versions_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last software program and its version are accessed by converting the dictionary keys to a list and selecting the last key ([-1] index).

  • The corresponding version of the last software is printed.

41.space_missions_dict.py

Creating the Dictionary of Space Missions and Their Years:

space_missions_dict = {
    'Apollo 11': 1969,
    'Mars Rover': 2021,
    'Voyager 1': 1977,
    'Hubble Space Telescope': 1990,
    'International Space Station': 1998
}
  • The dictionary space_missions_dict is created, where the keys are the names of space missions, and the values are the years in which these missions occurred.

    Printing the Entire Dictionary:

print("The entire dictionary:", space_missions_dict)
  • This line prints the entire dictionary, showing all space missions along with their years.

    Accessing and Printing the Year of the 3rd Mission (Voyager 1):

third_mission_year = list(space_missions_dict.values())[2]  # Index 2 for the 3rd item
print("\nThe year of the 3rd mission (Voyager 1):", third_mission_year)
  • The year of the 3rd mission (Voyager 1) is accessed by converting the dictionary values into a list and selecting the value at index 2 (because Python uses 0-based indexing).

  • The year of Voyager 1 (1977) is printed.

    Updating the Year of the 2nd Mission (Mars Rover):

space_missions_dict['Mars Rover'] = 2020  # Updating the year of the Mars Rover mission
print("\nUpdated year of the 2nd mission (Mars Rover):", space_missions_dict['Mars Rover'])
  • The year of the 2nd mission (Mars Rover) is updated from 2021 to 2020.

  • The updated year is printed.

    Deleting the 4th Mission (Hubble Space Telescope) from the Dictionary:

del space_missions_dict['Hubble Space Telescope']
print("\nDictionary after deleting the 4th mission (Hubble Space Telescope):", space_missions_dict)
  • The 4th mission (Hubble Space Telescope) is deleted from the dictionary using the del statement.

  • The dictionary is printed again after the deletion, showing the remaining missions.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(space_missions_dict.keys())[-1]
last_value = space_missions_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last mission and its year are accessed by converting the dictionary keys into a list and selecting the last key ([-1] index).

  • The corresponding year of the last mission is printed.

42.space_telescope_missions_dict.py

Creating the Dictionary of Space Telescopes and Their Missions:

space_telescope_missions_dict = {
    'Hubble Space Telescope': 'Hubble Deep Field',
    'James Webb Space Telescope': 'First Light',
    'Chandra X-ray Observatory': 'Deep Field Survey',
    'Spitzer Space Telescope': 'Exoplanet Exploration',
    'Kepler Space Telescope': 'Kepler Planet Search'
}
  • The dictionary space_telescope_missions_dict is created, where the keys are the names of space telescopes, and the values are their respective missions.

    Printing the Entire Dictionary:

print("The entire dictionary:", space_telescope_missions_dict)
  • This line prints the entire dictionary, showing all space telescopes along with their corresponding missions.

    Accessing and Printing the Mission of the 3rd Telescope (Chandra X-ray Observatory):

third_telescope_mission = list(space_telescope_missions_dict.values())[2]  # Index 2 for the 3rd telescope
print("\nThe mission of the 3rd telescope (Chandra X-ray Observatory):", third_telescope_mission)
  • The mission of the 3rd telescope (Chandra X-ray Observatory) is accessed by converting the dictionary values into a list and selecting the value at index 2 (since Python uses 0-based indexing).

  • The mission Deep Field Survey of the Chandra X-ray Observatory is printed.

    Updating the Mission of the 1st Telescope (Hubble Space Telescope):

space_telescope_missions_dict['Hubble Space Telescope'] = 'Hubble Ultra Deep Field'  # Updating the mission
print("\nUpdated mission of the 1st telescope (Hubble Space Telescope):", space_telescope_missions_dict['Hubble Space Telescope'])
  • The mission of the 1st telescope (Hubble Space Telescope) is updated from Hubble Deep Field to Hubble Ultra Deep Field.

  • The updated mission is printed.

    Deleting the 4th Telescope (Spitzer Space Telescope) from the Dictionary:

del space_telescope_missions_dict['Spitzer Space Telescope']
print("\nDictionary after deleting the 4th telescope (Spitzer Space Telescope):", space_telescope_missions_dict)
  • The 4th telescope (Spitzer Space Telescope) is deleted from the dictionary using the del statement.

  • The dictionary is printed again after the deletion, showing the remaining telescopes and missions.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(space_telescope_missions_dict.keys())[-1]
last_value = space_telescope_missions_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last telescope and its mission are accessed by converting the dictionary keys into a list and selecting the last key ([-1] index).

  • The corresponding mission of the last telescope is printed.

43.sports_events_dict.py

Creating the Dictionary of Sports Events and Their Years:

sports_events_dict = {
    'Olympic Games': 2020,
    'FIFA World Cup': 2022,
    'Super Bowl': 2021,
    'Tour de France': 2020,
    'Wimbledon': 2021,
    'NBA Finals': 2022,
    'UEFA Champions League Final': 2021
}
  • The dictionary sports_events_dict contains keys as the names of sports events and their corresponding values as the years they occurred.

    Printing the Entire Dictionary:

print("The entire dictionary:", sports_events_dict)
  • This line prints the entire dictionary, showing all sports events and their years.

    Accessing and Printing the Year of the 3rd Sports Event (Super Bowl):

third_event_year = list(sports_events_dict.values())[2]  # Index 2 for the 3rd event
print("\nYear of the 3rd sports event (Super Bowl):", third_event_year)
  • The year of the 3rd event (Super Bowl) is accessed by converting the dictionary values to a list and selecting the value at index 2 (since Python uses 0-based indexing).

  • The year 2021 of the Super Bowl is printed.

    Updating the Year of the 6th Sports Event (NBA Finals):

sports_events_dict['NBA Finals'] = 2023
print("\nUpdated year of the 6th sports event (NBA Finals):", sports_events_dict['NBA Finals'])
  • The year of the 6th event (NBA Finals) is updated from 2022 to 2023.

  • The updated year 2023 is printed.

    Deleting the 5th Sports Event (Wimbledon) from the Dictionary:

del sports_events_dict['Wimbledon']
print("\nDictionary after deleting the 5th sports event (Wimbledon):", sports_events_dict)
  • The 5th event (Wimbledon) is deleted from the dictionary using the del statement.

  • The dictionary is printed again after the deletion, showing the remaining events and years.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(sports_events_dict.keys())[-1]
last_value = sports_events_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last event and its year are accessed by converting the dictionary keys into a list and selecting the last key using index [-1].

  • The corresponding year of the last event is printed.

44.sports_players_dict.py

Creating the Dictionary of Sports and Famous Players:

sports_players_dict = {
    'Football': 'Lionel Messi',
    'Basketball': 'Michael Jordan',
    'Tennis': 'Roger Federer',
    'Cricket': 'Sachin Tendulkar',
    'Baseball': 'Babe Ruth',
    'Boxing': 'Muhammad Ali',
    'Golf': 'Tiger Woods',
    'Rugby': 'Jonah Lomu',
    'Hockey': 'Wayne Gretzky',
    'Athletics': 'Usain Bolt'
}
  • The dictionary sports_players_dict contains sports as the keys and their most famous players as the values.

    Printing the Entire Dictionary:

print("The entire dictionary:", sports_players_dict)
  • This prints the entire dictionary, showing the sport names and their corresponding famous players.

    Accessing and Printing the Player of the 4th Sport (Cricket):

fourth_sport_player = list(sports_players_dict.values())[3]  # Index 3 for the 4th sport
print("\nThe player of the 4th sport (Cricket):", fourth_sport_player)
  • The value of the 4th sport (Cricket) is accessed by converting the dictionary values to a list and selecting the value at index 3 (since Python uses 0-based indexing).

  • The famous player of Cricket, which is Sachin Tendulkar, is printed.

    Updating the Player of the 6th Sport (Boxing):

sports_players_dict['Boxing'] = 'Floyd Mayweather'
print("\nUpdated player of the 6th sport (Boxing):", sports_players_dict['Boxing'])
  • The famous player of Boxing is updated from Muhammad Ali to Floyd Mayweather.

  • The updated player for Boxing, which is Floyd Mayweather, is printed.

    Deleting the 10th Sport (Athletics) from the Dictionary:

del sports_players_dict['Athletics']
print("\nDictionary after deleting the 10th sport (Athletics):", sports_players_dict)
  • The 10th sport (Athletics) is deleted from the dictionary using the del statement.

  • The dictionary is printed again, showing the sports and players after the deletion.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(sports_players_dict.keys())[-1]
last_value = sports_players_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last key-value pair (the last sport and its player) is accessed by converting the dictionary keys into a list and selecting the last key using index [-1].

  • The corresponding player for the last sport is printed.

45.state_capitals_dict.py

Creating the Dictionary of States and Their Capitals:

state_capitals_dict = {
    'California': 'Sacramento',
    'Texas': 'Austin',
    'Florida': 'Tallahassee',
    'New York': 'Albany',
    'Illinois': 'Springfield',
    'Pennsylvania': 'Harrisburg',
    'Ohio': 'Columbus',
    'Georgia': 'Atlanta',
    'North Carolina': 'Raleigh',
    'Michigan': 'Lansing'
}
  • This dictionary contains the states as keys and their respective capitals as values.

    Printing the Entire Dictionary:

print("The entire dictionary:", state_capitals_dict)
  • The entire dictionary is printed, showing the states and their capitals.

    Accessing and Printing the Capital of the 4th State (New York):

fourth_state_capital = list(state_capitals_dict.values())[3]  # Index 3 for the 4th state
print("\nThe capital of the 4th state (New York):", fourth_state_capital)
  • The capital of the 4th state (New York) is accessed by converting the dictionary values to a list and selecting the value at index 3 (since indexing starts at 0).

  • The capital of New York, which is Albany, is printed.

    Updating the Capital of the 9th State (North Carolina):

state_capitals_dict['North Carolina'] = 'Charlotte'  # Updating the capital
print("\nUpdated capital of the 9th state (North Carolina):", state_capitals_dict['North Carolina'])
  • The capital of North Carolina is updated from Raleigh to Charlotte.

  • The updated capital of North Carolina is printed.

    Deleting the 7th State (Ohio) from the Dictionary:

del state_capitals_dict['Ohio']
print("\nDictionary after deleting the 7th state (Ohio):", state_capitals_dict)
  • The state Ohio is deleted from the dictionary using the del statement.

  • The updated dictionary (after deletion) is printed, showing the states and capitals with Ohio removed.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(state_capitals_dict.keys())[-1]
last_value = state_capitals_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • The last key-value pair in the dictionary is accessed by converting the keys into a list and selecting the last one using index [-1].

  • The last state-capital pair is printed.

46.student_grades_dict.py

Creating the Dictionary of Students and Their Grades:

student_grades_dict = {
    'Student1': 'B',
    'Student2': 'C',
    'Student3': 'A',
    'Student4': 'B',
    'Student5': 'D'
}
  • The dictionary student_grades_dict holds student names as keys and their respective grades as values.

    Printing the Entire Dictionary:

print("Student Grades Dictionary:", student_grades_dict)
  • This line prints the entire dictionary, displaying all students and their grades.

    Accessing and Printing the Grade of the 3rd Student:

print("Grade of third student:", student_grades_dict['Student3'])
  • The grade of Student3 is accessed directly using the key 'Student3', and it's printed. The expected output would be A since that's the grade for Student3.

    Updating the Grade of the 2nd Student:

student_grades_dict['Student2'] = 'A'
  • The grade of Student2 is updated from 'C' to 'A'.

  • The updated dictionary is printed in the next step.

    Printing the Updated Dictionary:

print("Updated Student Grades Dictionary:", student_grades_dict)
  • After the grade update, the dictionary is printed to show the new grades for all students, including the updated grade for Student2.

    Deleting the Entry of the 5th Student:

del student_grades_dict['Student5']
  • The entry for Student5 is deleted using the del statement, effectively removing the student and their grade from the dictionary.

    Printing the Updated Dictionary After Deletion:

print("Dictionary after deleting Student5:", student_grades_dict)
  • After deletion, the dictionary is printed again to show that Student5 has been removed.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(student_grades_dict.keys())[-1]
last_value = student_grades_dict[last_key]
print(f"Last key-value pair in the dictionary: {last_key}: {last_value}")
  • The last key-value pair in the dictionary is accessed by first converting the keys to a list and then selecting the last one using the index [-1].

  • The last key-value pair is printed in the format key: value.

47.technology_innovators_dict.py

Creating the Dictionary of Technologies and Innovators:

technology_innovators_dict = {
    'Telephone': 'Alexander Graham Bell',
    'Light Bulb': 'Thomas Edison',
    'Airplane': 'Wright Brothers',
    'Computer': 'Charles Babbage',
    'Internet': 'Tim Berners-Lee',
    'Electric Motor': 'Nikola Tesla',
    'Laser': 'Theodore Maiman',
    'Smartphone': 'Steve Jobs'
}
  • This dictionary stores technologies as keys and their corresponding innovators as values.

    Printing the Entire Dictionary:

print("The entire dictionary:")
print(technology_innovators_dict)
  • This prints the entire technology_innovators_dict to show all the technologies and their innovators.

    Accessing and Printing the Innovator of the 4th Technology (Computer):

fourth_technology_innovator = list(technology_innovators_dict.values())[3]  # Index 3 for the 4th technology
print("\nInnovator of the 4th technology (Computer):", fourth_technology_innovator)
  • This accesses the innovator of the 4th technology (Computer). Since dictionaries are unordered, we convert the values to a list and access the value at index 3, which corresponds to 'Charles Babbage'.

    Updating the Innovator of the 2nd Technology (Light Bulb):

technology_innovators_dict['Light Bulb'] = 'Joseph Swan'
print("\nUpdated innovator of the 2nd technology (Light Bulb):", technology_innovators_dict['Light Bulb'])
  • The innovator of the Light Bulb is updated from Thomas Edison to Joseph Swan.

    Deleting the 6th Technology (Electric Motor):

del technology_innovators_dict['Electric Motor']
print("\nDictionary after deleting the 6th technology (Electric Motor):")
print(technology_innovators_dict)
  • The entry for the Electric Motor is deleted using the del statement. The updated dictionary is printed to show the removal.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(technology_innovators_dict.keys())[-1]
last_value = technology_innovators_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • This retrieves the last key-value pair in the dictionary. It first converts the dictionary keys into a list, accesses the last one using the index [-1], and then prints the corresponding value.

48.technology_inventors_dict.py

Creating the Dictionary of Technologies and Inventors:

technology_inventors_dict = {
    'Telephone': 'Alexander Graham Bell',
    'Lightbulb': 'Thomas Edison',
    'Airplane': 'Wright Brothers',
    'Computer': 'Charles Babbage',
    'Internet': 'Tim Berners-Lee',
    'Printing Press': 'Johannes Gutenberg'
}
  • This dictionary holds technologies as keys and their corresponding inventors as values.

    Printing the Entire Dictionary:

print("The entire dictionary:", technology_inventors_dict)
  • This will display the entire dictionary, showing each technology and its inventor.

    Accessing and Printing the Inventor of the 4th Technology (Computer):

fourth_technology_inventor = list(technology_inventors_dict.values())[3]  # Index 3 for the 4th item
print("\nThe inventor of the 4th technology (Computer):", fourth_technology_inventor)
  • The values() of the dictionary are converted into a list, and the inventor of the 4th technology (Computer) is accessed using index 3 (since indexing starts from 0).

    Updating the Inventor of the 2nd Technology (Lightbulb):

technology_inventors_dict['Lightbulb'] = 'Humphry Davy'  # Updating the inventor of the Lightbulb
print("\nUpdated inventor of the 2nd technology (Lightbulb):", technology_inventors_dict['Lightbulb'])
  • The inventor of the Lightbulb is updated from Thomas Edison to Humphry Davy.

    Deleting the 6th Technology (Printing Press):

del technology_inventors_dict['Printing Press']
print("\nDictionary after deleting the 6th technology (Printing Press):", technology_inventors_dict)
  • The entry for the Printing Press is deleted using del. The dictionary is then printed without this entry.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(technology_inventors_dict.keys())[-1]
last_value = technology_inventors_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • To find the last key-value pair, the keys of the dictionary are converted into a list, and the last key-value pair is accessed using [-1].

49.university_courses_dict.py

Creating the Dictionary of Universities and Courses:

university_courses_dict = {
    'Harvard University': 'Computer Science',
    'Stanford University': 'Electrical Engineering',
    'Massachusetts Institute of Technology': 'Physics',
    'University of California, Berkeley': 'Biology',
    'University of Oxford': 'Law',
    'Cambridge University': 'Mathematics',
    'University of Chicago': 'Economics',
    'Princeton University': 'History'
}
  • The dictionary holds the names of universities as keys and their popular courses as values.

    Printing the Entire Dictionary:

print("The entire dictionary:", university_courses_dict)
  • This will print out the entire dictionary, showing all the universities and their corresponding courses.

    Accessing and Printing the Course of the 3rd University (Massachusetts Institute of Technology):

third_university_course = list(university_courses_dict.values())[2]  # Index 2 for the 3rd item
print("\nThe course of the 3rd university (Massachusetts Institute of Technology):", third_university_course)
  • The values() of the dictionary are converted into a list, and the course of the 3rd university (Massachusetts Institute of Technology) is accessed using index 2.

    Updating the Course of the 5th University (University of Oxford):

university_courses_dict['University of Oxford'] = 'Philosophy'
print("\nUpdated course of the 5th university (University of Oxford):", university_courses_dict['University of Oxford'])
  • The course of University of Oxford is updated from Law to Philosophy.

    Deleting the 7th University (University of Chicago):

del university_courses_dict['University of Chicago']
print("\nDictionary after deleting the 7th university (University of Chicago):", university_courses_dict)
  • The entry for University of Chicago is deleted from the dictionary.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(university_courses_dict.keys())[-1]
last_value = university_courses_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • To find the last key-value pair, the keys are converted to a list and the last key-value pair is accessed using [-1].

50.video_game_platforms_dict.py

Creating the Dictionary of Video Games and Platforms:

video_game_platforms_dict = {
    'The Last of Us': 'PlayStation 3, PlayStation 4',
    'Minecraft': 'PC, Xbox, PlayStation, Switch',
    'Fortnite': 'PC, Xbox, PlayStation, Switch',
    'Call of Duty: Warzone': 'PC, Xbox, PlayStation',
    'Red Dead Redemption 2': 'PC, Xbox, PlayStation',
    'Cyberpunk 2077': 'PC, Xbox, PlayStation',
    'Super Mario Odyssey': 'Switch',
    'The Witcher 3: Wild Hunt': 'PC, Xbox, PlayStation, Switch'
}
  • This dictionary contains 8 video games as keys and their respective platforms as values.

    Printing the Entire Dictionary:

print("The entire dictionary:", video_game_platforms_dict)
  • This will print the entire dictionary, displaying each game and its associated platforms.

    Accessing and Printing the Platform of the 2nd Video Game (Minecraft):

second_game_platform = list(video_game_platforms_dict.values())[1]  # Index 1 for the 2nd item
print("\nThe platform of the 2nd video game (Minecraft):", second_game_platform)
  • We access the platform of the 2nd game, which is Minecraft, by getting the value at index 1.

    Updating the Platform of the 6th Video Game (Cyberpunk 2077):

video_game_platforms_dict['Cyberpunk 2077'] = 'PC, Xbox, PlayStation, Stadia'  # Updating the platform
print("\nUpdated platform of the 6th video game (Cyberpunk 2077):", video_game_platforms_dict['Cyberpunk 2077'])
  • The platform of Cyberpunk 2077 is updated from 'PC, Xbox, PlayStation' to 'PC, Xbox, PlayStation, Stadia'.

    Deleting the 4th Video Game (Call of Duty: Warzone):

del video_game_platforms_dict['Call of Duty: Warzone']
print("\nDictionary after deleting the 4th video game (Call of Duty: Warzone):", video_game_platforms_dict)
  • The entry for Call of Duty: Warzone is deleted from the dictionary.

    Printing the Last Key-Value Pair in the Dictionary:

last_key = list(video_game_platforms_dict.keys())[-1]
last_value = video_game_platforms_dict[last_key]
print("\nThe last key-value pair in the dictionary:", (last_key, last_value))
  • To find the last key-value pair in the dictionary, the keys are converted to a list and the last item is accessed using [-1].

RonaDecio/Decio_Master_Python_Dictionaries_Data_Structures