Does anyone else think there should be a flatten () function, which just turns a multi-dimensional list into a one-dimensional list in the order it's in. e.g.
[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
I have had to flatten lists quite a few times and it's quite tedious to type out. It feels like this should be something built in to python, anyone else think this way?
I have had to flatten lists quite a few times and it's quite
tedious to type out. It feels like this should be something
built in to python, anyone else think this way?
. I never understood "yield from" until just now, when I was
thinking, "Maybe this could be the piece that fits in here!"
Does anyone else think there should be a flatten () function, which just turns a multi-dimensional list into a one-dimensional list in the order it's in. e.g.
[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
I have had to flatten lists quite a few times and it's quite tedious to
type out. It feels like this should be something built in to python,
anyone else think this way?
Does anyone else think there should be a flatten () function, which just turns a multi-dimensional list into a one-dimensional list in the order it's in. e.g.
[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
I have had to flatten lists quite a few times and it's quite tedious to type out. It feels like this should be something built in to python, anyone else think this way?
... flattened += elementl = [[1,2,3],[4,5,6,7],[8,9]]
flattened = list()
for element in l:
[1, 2, 3, 4, 5, 6, 7, 8, 9]flattened
[1, 2, 3, 4, 5, 6, 7, 8, 9]import itertools as it
iter_flattened = it.chain( *l )
list( iter_flattened )
Does anyone else think there should be a flatten () function, which just turns a multi-dimensional list into a one-dimensional list in the order it's in. e.g.
[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
I have had to flatten lists quite a few times and it's quite tedious to type out. It feels like this should be something built in to python, anyone else think this way?
ram@zedat.fu-berlin.de (Stefan Ram) writes:
. I never understood "yield from" until just now, when I was
thinking, "Maybe this could be the piece that fits in here!"
PS: If I'm starting to think about it: Having succeeded
after using it by trial in one case does not mean that I
have understood it!
Does anyone else think there should be a flatten () function, which just turns a multi-dimensional list into a one-dimensional list in the order
it's in. e.g.
[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
I have had to flatten lists quite a few times and it's quite tedious to
type out. It feels like this should be something built in to python, anyone else think this way?
Does anyone else think there should be a flatten () function, which just turns a multi-dimensional list into a one-dimensional list in the order it's in. e.g.
[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
I have had to flatten lists quite a few times and it's quite tedious to type out. It feels like this should be something built in to python, anyone else think this way?
[1, 2, 3, 4, 5, 6, 7, 8, 9]lst = [[1,2,3],[4,5,6,7],[8,9]]
list(itertools.chain.from_iterable(lst))
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 60:06:07 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,756 |