Codepath

Festival Lineup

Unit 2 Session 1 (Click for link to problem statements)

U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Q: What is the problem asking for?

    • A: The problem asks to map each artist from a list to their respective set time using dictionaries.
  • Q: What are the inputs?

    • A: Two lists, artists and set_times, both of equal length n.
  • Q: What are the outputs?

    • A: A dictionary where each artist from the artists list is mapped to their corresponding set time from the set_times list.
  • Q: Can the lists be empty?

    • A: Yes, both lists can be empty, resulting in an empty dictionary as output.
  • Q: Is the order of elements important?

    • A: Yes, the order is important as artists[i] corresponds to set_times[i].

P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Create a dictionary by iterating over the lists and mapping each artist to their set time.

1) Initialize an empty dictionary `schedule`.
2) Iterate over the range of the length of the `artists` list.
   - For each index `i`, set `schedule[artists[i]]` to `set_times[i]`.
3) Return the dictionary `schedule`.

⚠️ Common Mistakes

  • Ensure that the lengths of artists and set_times are equal.
  • Handle empty lists by returning an empty dictionary.

I-mplement

def lineup(artists, set_times):
    schedule = {}
    for i in range(len(artists)):
        schedule[artists[i]] = set_times[i]
    return schedule
Fork me on GitHub