Why enum comprehension with map () function in python can return None
Because it print
returns None
?
So, printing is done ( 4, 5, 6, 7,
) and then list comprehension ( [None, None, None, None]
) is returned
What you want to do is use join:
>>> ', '.join(str(i) for i in map(inc, counters))
'4, 5, 6, 7'
or use the argument sep
to print (I don't have python3 right now, but something like this :)
print(*map(inc, counters), sep=', ')
source to share
print is a function, but it returns None
why you don't get
Do it
In [3]: [i for i in map(abs, counters)]
Out[3]: [1, 2, 3, 4]
In [7]: a = print(1234)
1234
In [11]: print(a)
None
[print(i, end=', ') for i in map(inc, counters)]
so when you do this it print
prints i
1, 2, 3, 4 , and then each time it list comprehension
returns the result which is None
hence No, None, None, None
source to share