Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

performance of extend vs append loop

# TLDR; Extend is faster than a an append loop
def append(alist, iterable):
    for item in iterable:
        alist.append(item)
        
def extend(alist, iterable):
    alist.extend(iterable)

import timeit

>>> min(timeit.repeat(lambda: append([], "abcdefghijklmnopqrstuvwxyz")))
2.867846965789795
>>> min(timeit.repeat(lambda: extend([], "abcdefghijklmnopqrstuvwxyz")))
0.8060121536254883
Comment

PREVIOUS NEXT
Code Example
Python :: np where pandas with 3 choices 
Python :: how to create decorator function in django 
Python :: how to convert 2 dimensional in 1 dimensional array 
Python :: import baseestimator 
Python :: how to resume request downloads 
Python :: how to serial print line break 
Python :: function to sort a list of points based on their x and y-coordinates 
Python :: df sum 
Python :: python pass function as argument 
Python :: python text to speech arabic 
Python :: start application from python 
Python :: default arguments 
Python :: python transpose a list 
Python :: python class variable 
Python :: how to add a key in python dictionary 
Python :: TypeError: can only concatenate str (not "list") to str 
Python :: import one hot encoder 
Python :: how to update a python package 
Python :: bokeh bar chart 
Python :: pyplot.plot 
Python :: python editor online 
Python :: jupyter notebook set password 
Python :: stingray 
Python :: export an excel table to image with python 
Python :: wisdom 
Python :: matplotlib subplots share x axis 
Python :: python class variables 
Python :: sort pandas dataframe by specific column 
Python :: how to add number to string in python 
Python :: how to make a calculator 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =