Blog Detail

September 3, 2023

Python Sets Exercises

  • Which of the following options correctly identifies the keys and values in the dictionary?

                    my_dictionary = {"cat": "meow", "dog": "woof", "bird": "tweet"}
  • Imagine you are building a task management application. You have a dictionary representing a user’s tasks, where the keys are task IDs and the values are the corresponding task descriptions.

    Now, let’s say that the user has completed task ID 2 and you want to remove it from the tasks dictionary.

                    tasks = {
        1: "Complete project proposal",
        2: "Review meeting notes",
        3: "Submit expense report",
        4: "Follow up with clients"
    '' tasks[2]
  • What is the output of this code?

                    my_dictionary = {"cat": "meow", "dog": "woof", "bird": "tweet"}
  • Imagine you are building a student management system for a school. You have a dictionary representing a student’s information, including their name, grade level, and GPA.

    Now, let’s say that the student’s GPA has improved to 4.0, and you want to update the value of the ‘gpa’ key in the dictionary.

                    student_info = {
        "name": "John Doe",
        "grade_level": 10,
        "gpa": 3.8
  • Python Exercises for Sets

    • If you’ve faced difficulties with these exercises, take a look at Sets Module on my Python course.

    You can also share ‘Python Sets’ Exercises on your:
    X (Twitter)TelegramLinkedinFacebook – or on your favorite platform…

    Happy Coding!
    Behnam Khani