是否有內置的內容來說明兩個列表之間的置換差異?例如。Python置換差異
difference("ijk", "ikj") = (0,2,1)
difference("jik", "ikj") = (2,0,1)
etc ...
哎呀,算了,這裏是一個片段
[a.index(i) for i in b]
是否有內置的內容來說明兩個列表之間的置換差異?例如。Python置換差異
difference("ijk", "ikj") = (0,2,1)
difference("jik", "ikj") = (2,0,1)
etc ...
哎呀,算了,這裏是一個片段
[a.index(i) for i in b]
很簡單...
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)
是否足夠短?
tuple([s2.index(p) for p in s1])
請定義'置換difference' – Daenyth
這是一個謎,你必須首先弄清楚的問題是什麼:/ –
@Dae指數變換一個列表進入另一個。 – Anycorn