Skipping every other element after the first

后端 未结 13 2198
深忆病人
深忆病人 2020-12-04 21:13

I have the general idea of how to do this in Java, but I am learning Python and not sure how to do it.

I need to implement a function that returns a list containing

13条回答
  •  感动是毒
    2020-12-04 21:43

    items = range(10)
    print items
    >>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    print items[1::2] # every other item after the second; slight variation
    >>> [1, 3, 5, 7, 9]
    ]
    

提交回复
热议问题