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

    Oct 31, 2008 · 677 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 …

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

    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 …

  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 …

  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", …

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

    405 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 …

  7. 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(...

  8. python - List extend with a generator expression referencing the …

    Sep 28, 2022 · I understand that in order to execute extend, it must first evaluate the generator expression, which in turn references the original list. But here's how I would assume it works …

  9. Can I extend list in Python with prepend elements instead of …

    Can I extend list in Python with prepend elements instead of append? Asked 12 years, 1 month ago Modified 4 years, 6 months ago Viewed 38k times

  10. 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.