Removing range of items from a list

前端 未结 2 1584
攒了一身酷
攒了一身酷 2021-01-28 13:35

Is there a way to remove items in a range in list? For example: a = [1,2,3,4,5]. How to remove items from 3 to 5?

2条回答
  •  感情败类
    2021-01-28 14:31

    Yes, you can use a list comprehension to filter the data.

    a = [1,2,3,4,5]
    print([x for x in a if 3 <= x <= 5])
    

提交回复
热议问题