python 使用列表或元祖作为列表索引

2020-11-01  本文已影响0人  纵春水东流

python本身不支持列表或元祖作为列表索引

def list_indice(x,y):
    """
    python not suport list or tuple as indice,use this function to do this job
    x:a list will be indiced
    y:a list or tuple as indice,you shoul know that y list must all integer!!! or rise error
    """
    return [x[i] for i in y]

上一篇 下一篇

猜你喜欢

热点阅读