Skipping every other element after the first

后端 未结 13 2172
深忆病人
深忆病人 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:44

    Slice notation a[start_index:end_index:step]

    return a[::2]
    

    where start_index defaults to 0 and end_index defaults to the len(a).

提交回复
热议问题