LISP cons in python

后端 未结 6 1985
小鲜肉
小鲜肉 2021-01-12 07:10

Is there an equivalent of cons in Python? (any version above 2.5)

If so, is it built in? Or do I need easy_install do get a module?

6条回答
  •  礼貌的吻别
    2021-01-12 07:26

    Note that Python's lists are implemented as vectors, not as linked lists. You could do lst.insert(0, val), but that operation is O(n).

    If you want a data structure that behaves more like a linked list, try using a Deque.

提交回复
热议问题