Python slice first and last element in list

后端 未结 17 1438
有刺的猬
有刺的猬 2020-12-02 17:54

Is there a way to slice only the first and last item in a list?

For example; If this is my list:

>>> some_list
[\'1\', \'B\', \'3\', \'D\',          


        
17条回答
  •  独厮守ぢ
    2020-12-02 18:55

    Actually, I just figured it out:

    In [20]: some_list[::len(some_list) - 1]
    Out[20]: ['1', 'F']
    

提交回复
热议问题