← Back to challenges

Fit the Pattern

PythonHardarraysfunctional_programming

Instructions

Create a function that checks if the sub-lists in a list adhere to the specified pattern.

Examples

check_pattern([[1, 1], [2, 2], [1, 1], [2, 2]], "ABAB") ➞ True

check_pattern([[1, 2], [1, 3], [1, 4], [1, 2]], "ABCA") ➞ True

check_pattern([[1, 2, 3], [1, 2, 3], [3, 2, 1], [3, 2, 1]], "AABB") ➞ True

check_pattern([[8, 8, 8, 8], [7, 7, 7, 7], [6, 6, 6, 6], [5, 5, 5, 5]], "ABCD") ➞ True

check_pattern([[8, 8, 8, 8], [7, 7, 7, 7], [6, 6, 6, 6], [5, 5, 5, 5]], "DCBA") ➞ True

Notes

  • The length of the pattern will always be the same as the length of the (main) list.
  • The pattern does not necessarily have to be alphabetically ordered (see last example).
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.