Removing elements that have consecutive duplicates

后端 未结 9 1387
眼角桃花
眼角桃花 2020-11-22 10:02

I was curios about the question: Eliminate consecutive duplicates of list elements, and how it should be implemented in Python.

What I came up with is this:

9条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 10:32

    Oneliner in pure Python

    [v for i, v in enumerate(your_list) if i == 0 or v != your_list[i-1]]
    

提交回复
热议问题