fb pixel

Introduction to Python

  • Profound Academy

    • Status
      • 1
        Input and Output
      • 2
        Variables and Integer Arithmetic
      • 3
        Conditional Operators
      • 4
        Advanced Conditions - Nesting
      • 5
        Types and Variables
      • 6
      • 7
      • 8
        For Loops
      • 9
        While Loops
      • 10
        continue, break, while...else
      • 11
        String and List methods
      • 12
        Nested Loops
      • 13
        List Comprehension
      • 14
        Tuples and Sets
      • 15
      • 16
      • 17
        Functions 2
      • 18
        Lambda and higher-order functions
      • 19

  • Gym memberships

    A big gym network has several branches at different locations. They find it sometimes hard to keep track of the people that have their memberships. They know the name of the people and where their gym is, but they would like to know the list of people for each location.
    The first line of the input contains a single integer n the number of people who have signed up for a gym membership. The next n lines contain " - " separated person's name and the location of the gym where they have their membership. The next line contains a single integer q, the number of location queries. The following q lines contain the names of the locations.
    The program should print q lines. Each line should contain space-separated names of people who are attending the gyms at that location.
    5 Bob - Green st. 1 Lucy - Park Dr. 25 Anna - Green st. 1 Lucas - Sharon Park Dr. 8 Simon - Sharon Park Dr. 8 3 Sharon Park Dr. 8 Green st. 1 Park Dr. 25
    Lucas Simon Bob Anna Lucy
    Note: The names should be in the order of appearance in the input
    To check your solution you need to sign in
    Sign in to continue