ss.items() will give iterability, which gives tuples at each iteration. In your lambda function, you defined it to accept two parameters, but the tuple will be considered as one argument. Thus, the value is not passed to the second parameter.
You can fix it like this:
print(list(map(lambda args: int(args[1]), ss.items())))
If you ignore the keys anyway, just use ss.values() , like this
print(list(map(int, ss.values())))
Otherwise, as suggested by Ashwini Chodhari using itertools.starmap ,
from itertools import starmap print(list(starmap(lambda key, value: int(value), ss.items())))
I would prefer a way to understand List
print([int(value) for value in ss.values()]) # [3, 2]
In Python 2.x, you could do it like this:
print map(lambda (key, value): int(value), ss.items())
This function is called unpacking Tuple parameters. But this is removed in Python 3.x. Read more about this in PEP-3113
thefourtheye
source share