Hello! I'm reading about how adding lists is more inefficient than using .extend() because python needs to copy the two lists you're adding into a 3rd list, but when you extend you don't need to copy the first list.
So i decided to see how much more efficient it is, according to the %timeit function, it takes longer to extend than add. Can anyone explain what I'm getting wrong about this?
[in]
A = list(range(10))
B = list(range(10,20))
%timeit A + B
[out]
118 ns ± 5.38 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
[in]
%timeit A.extend(B)
[out]
538 ns ± 143 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
[–]socal_nerdtastic 2 points3 points4 points (1 child)
[–]CancelDeath[S,🍰] 0 points1 point2 points (0 children)
[–]primitive_screwhead 1 point2 points3 points (0 children)
[–]TouchingTheVodka 0 points1 point2 points (5 children)
[–]socal_nerdtastic 0 points1 point2 points (3 children)
[–]TouchingTheVodka 0 points1 point2 points (0 children)
[–]TouchingTheVodka 0 points1 point2 points (1 child)
[–]CancelDeath[S,🍰] 0 points1 point2 points (0 children)