I have a nested list comprehension, when I print the output, it gives me generator object, I was expecting a tuple.
vector = [[1,2],[2,3],[3,4]]
res = (x for y in vector for x in y if x%2 == 0)
print(res)
I thought since I have small bracket for res assignment, I thought the result will be tuple, but it gives me a generator object.
But when I use a traditional approach, it gives me a list.
lst = []
for y in vector:
print(y)
for x in y:
print(x)
if x%2 == 0:
lst.append(x)
print(lst)
It looks clear here that it gives a list there is no confusion here in the second one, but the first one is little confusing as why it gives a generator object.