What's the idiomatic syntax for prepending to a short python list?

后端 未结 5 1640
清酒与你
清酒与你 2020-11-27 09:42

list.append() is the obvious choice for adding to the end of a list. Here\'s a reasonable explanation for the missing list.prepend(). Assuming my

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 10:18

    The s.insert(0, x) form is the most common.

    Whenever you see it though, it may be time to consider using a collections.deque instead of a list.

提交回复
热议问题