using map(int, raw_input().split())

Aswin Murugesh picture Aswin Murugesh · Jun 15, 2013 · Viewed 65.5k times · Source

Though I like python very much, When I need to get multiple integer inputs in the same line, I prefer C/C++. If I use python, I use:

a = map(int, raw_input().split())

Is this the only way or is there any pythonic way to do it? And does this cost much as far as time is considered?

Answer

phil-ociraptor picture phil-ociraptor · May 24, 2014

List comprehensions!

Intuitive and pythonic:

a = [int(i) for i in raw_input().split()]

Check out this discussion here: Python List Comprehension Vs. Map