Generator comprehension - list None

Sayth Renshaw flebber.crue at gmail.com
Tue Oct 18 07:43:23 EDT 2016


I was solving a problem to create a generator comprehension with 'Got ' and a number for each in range 10.

This I did however I also get a list of None. I don't understand where none comes from. Can you please clarify?

a = (print("Got {0}".format(num[0])) for num in enumerate(range(10)))

# for item in a:
# 	print(item)
	
b = list(a)
print(b)

Output
Got 0
Got 1
Got 2
Got 3
Got 4
Got 5
Got 6
Got 7
Got 8
Got 9
[None, None, None, None, None, None, None, None, None, None]
=> None

Thanks

Sayth




More information about the Python-list mailing list