【380】python 获取列表排序后的索引列表

参考:Equivalent of Numpy.argsort() in basic python? - Stack Overflow  

通过 enumerate 实现

[i for i,v in sorted(enumerate(['Vincent', 'Alex', 'Bill', 'Matthew']), key=lambda x:x[1])]

output:
[1, 2, 3, 0]

  

猜你喜欢

转载自www.cnblogs.com/alex-bn-lee/p/10556308.html