If we assume that the string s
contains all the letters of "the quick brown fox jumps over the lazy dog" but in a different order, and we want to rearrange them to form the original string, we can use the sorted
function to sort the letters in the string in alphabetical order, and then join them to form the original string:
main.py88 chars4 lines
Output:
main.py36 chars2 lines
Note that this approach only works if the input string contains exactly the same letters as the target string. If there are extra or missing letters, the output will not be correct.
gistlibby LogSnag