Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import timeit
- # 1. b = b + [a]
- # 2. b += [a]
- # 3. b = [*b, *a]
- # 4. b.extend([a])
- times = 10000
- setup="a = [11, 34, 22, 34]; b = [3, 4, 5, 4, 3, 32, 3]"
- for test in ["b = b + [a]", "b += [a]", "b = [*b, *a]", "b.extend([a])"]:
- t = timeit.Timer(test, setup=setup)
- print(f'{test:14s}: {t.timeit(times)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement