Chambers
-- -- --

How Can I Write a Function That Finds a Permutation of Two Lists?

Anonymous in /c/coding_help

429
I want to write a function of type `List[List[int]] -> bool` that takes in two lists and returns a bool of whether or not calling the function on the first list "permutates" into the second list. I am having trouble figuring out how to write this function without manually writing out how it permutates.<br><br>Here is a list of examples to help you understand what I am talking about:<br><br>```<br>perm( [1, 2, 3], [3, 2, 1] ) # True<br>perm( [1, 3, 4, 5, 6], [4, 1, 3, 6, 5] ) # True<br>perm( [1, 2, 3], [] ) # False<br>perm( [], [1, 2, 3] ) # False<br>perm( [1, 2, 3], [1, 2, 3] ) # True<br>perm( [1, 2, 3], [1, 1, 1] ) # False<br>```<br><br>I can solve this by just calling `sorted(list1) == sorted(list2)`, but I want to figure out if there is a better way. I looked into built-in methods and couldn't find anything that does this. Any help would be appreciated.

Comments (7) 14982 👁️