'If I am appending multiple elements to a list in python, is it more worth putting them all into a list then extending it? [duplicate]
For example:
lst.append(x)
lst.append(25)
lst.append(y)
Would it be better to write this:
lst.extend([x, 25, y])
Solution 1:[1]
If you are adding one element to the list use append each time. If instead you have a list of several elements to add to the list use extend which will effectively append each of the iterables of the argument provided.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | UpAndAdam |
