Skip to content

Instantly share code, notes, and snippets.

@shibukawa
Created March 1, 2019 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibukawa/9855449b7e5f789f711d27199b854b1d to your computer and use it in GitHub Desktop.
Save shibukawa/9855449b7e5f789f711d27199b854b1d to your computer and use it in GitHub Desktop.
>>> 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]
@shibukawa
Copy link
Author

setを、元の配列のindexでソート

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment