About 136,000 results
Open links in new tab
  1. What is the difference between Python's list methods append and …

    Oct 31, 2008 · 676 What is the difference between the list methods append and extend? .append() adds its argument as a single element to the end of a list. The length of the list itself will increase by one. …

  2. python - Concatenating two lists - difference between '+=' and extend ...

    ary.extend (ext) merely adds reference to "ext" list to the end of the "ary" list, resulting in less memory transactions. As a result, .extend works orders of magnitude faster and doesn't use any additional …

  3. python - Append vs extend efficiency - Stack Overflow

    As we can see, extend with list comprehension is still over two times faster than appending. Generator expressions appear noticeably slower than list comprehension. append_comp only introduces …

  4. python - Extending list returns None - Stack Overflow

    May 2, 2015 · It's overkill to use numpy if there's a built-in extend. Plus, it's a common pitfall to try to return a new list but modify existing in place, and the extend do not allow for it, hence safer.

  5. python - list extend () to index, inserting list elements not only to ...

    Sep 11, 2011 · I'm looking for the most pythonic way to implement a version of the list extend function, where it extends to a given index instead of the end of the list. a_list = [ "I", "rad", "list" ] ...

  6. python - List extend with a generator expression referencing the list ...

    Sep 28, 2022 · extend has a generator expression as the argument, so it goes ahead and evaluates the expression first generator expression is evaluated to [2, 4] now extend the original list a with [2, 4] …

  7. list - In Python, what is the difference between ".append ()" and ...

    In general, if you're appending/extended an existing list, and you want to keep the reference to the same list (instead of making a new one), it's best to be explicit and stick with the append ()/extend () methods.

  8. python - Extend list with another list in specific index ... - Stack ...

    Jan 15, 2023 · Closed 2 years ago. In python we can add lists to each other with the extend () method but it adds the second list at the end of the first list.

  9. How to inherit and extend a list object in Python?

    I am interested in using the python list object, but with slightly altered functionality. In particular, I would like the list to be 1-indexed instead of 0-indexed. E.g.: >> mylist = MyList(...

  10. How do I concatenate two lists in Python? - Stack Overflow

    404 How do I concatenate two lists in Python? As of 3.9, these are the most popular stdlib methods for concatenating two (or more) lists in Python. ... * A solution will qualify as a generalized solution if it …