In python how can I set multiple values of a list to zero simultaneously?

前端 未结 5 1147
南旧
南旧 2021-02-04 02:10

Conceptually, I want to do:

arr[20:] = 0

where arr is a list. How can I do this?

5条回答
  •  独厮守ぢ
    2021-02-04 03:05

    If you use list comprehension you make a copy of the list, so there is memory waste. Use list comprehension or slicing to make new lists, use for cicles to set your list items correctly.

提交回复
热议问题