← Back to challenges

Sort Words by a String

PythonHardsortingstrings

Instructions

Create a function that sorts words by a given string.

Examples

sort_by_string(["poof", "floof", "loop"], "flatp")
➞ ["floof", "loop", "poof"]

sort_by_string(["small", "big", "medium"], "sazymtb")
➞ ["small", "medium", "big"]

sort_by_string(["apple", "banana", "cherry", "date"], "dbca")
➞ ["date", "banana", "cherry", "apple"]

Notes

  • The string may have excess letters (see examples #1 and #2).
  • There will be unique starting letters in each list.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.