tnecniv
tnecniv

Reputation: 157

How to convert a string of numbers into a list of int in python3

sample input:

32 42 4 423 43 2 3

my code to convert the input into a list of integers:

mylist = map(int, (list(input().split(' '))))
print(mylist)

output of my code:

<map object at 0x7f0eb38f1d30>

Expected output:

[32, 42, 4, 423, 43, 2, 3]

Upvotes: 1

Views: 915

Answers (1)

Reut Sharabani
Reut Sharabani

Reputation: 31339

If you want a list use a list comprehension:

mylist = [int(x) for x in input.split(' ')]

The result of map is a map object, and you're getting it's representation.

You can convert it to a list:

mymap = map(int, (list(input().split(' '))))
print(list(mymap))

Upvotes: 1

Related Questions