I have a list of tuples and single floats
v = [(1., 2., 3.), (4., 5.), 6., 7.]
Now I want to flatten it with the good old list comprehension
[item for sublist in v for item in sublist]
But an error occurs as single floats are not iterable. What is the most efficient way to unroll this mixed list? I tried to go through the list and use isininstance() but once again, the list is not iterable.
EDIT: time comparisons so far
- numpy approach with hstack: 6.49 µs ± 100 ns per loop
- hasattr approach: 398 ns ± 2.11 ns per loop
- collections approach: 804 ns ± 1.27 ns per loop