I'm trying to convert the values of a list using the map
function but i am getting a strange result.
s = input("input some numbers: ")
i = map(int, s.split())
print(i)
gives:
input some numbers: 4 58 6
<map object at 0x00000000031AE7B8>
why does it not return ['4','58','6']?
You are using python 3 which returns generators instead of lists.
Call list(x)
on the variable after you assign it the map generator.
You need to do list(i)
to get ['4','58','6']
as map
in python 3 returns a generator instead of a list.
Also, as Lattyware pointed in the comment of the first answer you better do this:
i = [int(x) for x in s.split()]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With