I want to expand list in list that included in some not-iterable
objects to flat.
I tried to do this using list comprehension, but I get an error in not-iterable objects.
How to expand this list to flat?
# [[1, 2], 3] -> [1, 2, 3]
list = [[1, 2], 3]
flat = [item for sublist in list for item in sublist] # TypeError: 'int' object is not iterable
print(flat)
In my environment, numpy is installed in addition to the standard functions.
I tried numpy.concatenate(list).flat
, but I get an error.
# [[1, 2], 3] -> [1, 2, 3]
list = [[1, 2], 3]
flat = numpy.concatenate(list).flat # ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 0 dimension(s)
print(flat)