how to print list skipping one element each time in python without numpy?

前端 未结 3 1744
既然无缘
既然无缘 2021-01-20 08:03

given

samplelist = [100,101,102,103,104,105,106,107,108,109]

then I want output as below:

[100,[101,102,103,104,105,106,10         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-20 08:38

    use itertools.combinations():

    import itertools
    a = [100,101,102,103,104,105,106,107,108,109]
    list(itertools.combinations(a, len(a)-1))[::-1]
    

提交回复
热议问题