Function: python-util-popn

python-util-popn is a byte-compiled function defined in python.el.gz.

Signature

(python-util-popn LST N)

Documentation

Return LST first N elements.

N should be an integer, when negative its opposite is used. When N is bigger than the length of LST, the list is returned as is.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-util-popn (lst n)
  "Return LST first N elements.
N should be an integer, when negative its opposite is used.
When N is bigger than the length of LST, the list is
returned as is."
  (let* ((n (min (abs n)))
         (len (length lst))
         (acc))
    (if (> n len)
        lst
      (while (< 0 n)
        (setq acc (cons (car lst) acc)
              lst (cdr lst)
              n (1- n)))
      (reverse acc))))