Python permutation difference
Is there something built-in to tell the permutation difference between two list? E.g.
difference("ijk", "ikj") = (0,2,1开发者_如何学Go)
difference("jik", "ikj") = (2,0,1)
etc ...
oops, nevermind, here is a snippet
[a.index(i) for i in b]
Pretty simple...
def difference(after, before):
return tuple(before.index(x) for x in after)
print difference('ijk', 'ikj') # (0, 2, 1)
print difference('jik', 'ikj') # (2, 0, 1)
Is this short enough?
tuple([s2.index(p) for p in s1])
精彩评论