---
title: "Hynek Černoch (@hynekcer) | Hashnode"
description: "Hynek Černoch (@hynekcer) writes on Hashnode. Read their latest articles and follow their work."
url: "https://hashnode.com/@hynekcer"
---

@hynekcer

# Hynek Černoch

@hynekcer · Joined December 2020

## Comments

[This require a copy.deepcopy() to prevent a side effects because the original input parameter is completely broken by this function.](https://hashnode.com/posts/python-flatten-list/5fd49556b6e5766805757aa7/comment/5fdbceceb78ac62dff80a5c9#reply-5fdc35ddb78ac62dff80aac7)

Reply · Article · Dec 18, 2020 · [7 Different Ways to Flatten a List of Lists in Python](https://hashnode.com/posts/python-flatten-list/5fd49556b6e5766805757aa7)

[All functions measured by a line %timeit some\_function(l) are measured incorrectly. A time in about hundreds of nanoseconds to get a list of 9 \* 1000 numbers is a nonsense. You will see that the result doesn't depend on a number of items. It is because any code after a yield command is postponed until you enumerate the output values. If you put a slow sleep command after a yield line then you will see no difference because it run never. Even a generator expression command %timeit (x for x in range(1000000000)) is similarly fast as the same for range(1). A correct measurement is by %timeit list(some\_function(l)) or %timeit for \_ in some\_function(l): pass The fastest code for flattening is flatten\_chain(l) because the expression itertools.chain(\*lst) uses only a library function call and no Python loops.](https://hashnode.com/posts/python-flatten-list/5fd49556b6e5766805757aa7/comment/5fdc3422b78ac62dff80aa9a)

Comment · Article · Dec 18, 2020 · [7 Different Ways to Flatten a List of Lists in Python](https://hashnode.com/posts/python-flatten-list/5fd49556b6e5766805757aa7)
