Created
March 1, 2019 11:03
-
-
Save shibukawa/9855449b7e5f789f711d27199b854b1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> a = [ 9, 5, 4, 2, 1] | |
>>> b = [ 2, 4, 7, 8, 10] | |
>>> def sortset(s, a): | |
... return sorted(s, key=lambda e: a.index(e)) | |
... | |
>>> sortset(set(a) - set(b), a + b) | |
[9, 5, 1] | |
>>> sortset(set(b) - set(a), a + b) | |
[7, 8, 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setを、元の配列のindexでソート