List Intersection

Easy
11
91.5% Acceptance

In this lab, you will be implementing and testing a Python function named common_elements. This function will take two lists as input and return a list of elements that are common to both lists. The order of the elements in the output does not matter.

Your task is to ensure that your function handles different scenarios correctly, as outlined in the provided challenges.

Function Requirements:

  • The function should be named common_elements.
  • It must take two lists as input.
  • It should return a list of common elements. If there are no common elements, it should return an empty list.

Examples:

  1. Example 1:

    • Input: [1, 2, 3, 4] and [2, 5, 6, 1]
    • Output: [1, 2] or [2, 1]
  2. Example 2:

    • Input: [7, 8, 9] and [10, 11, 12]
    • Output: [] (since there are no common elements)

Remember, the focus is on writing a function that not only works but also handles various edge cases and inputs effectively.