How to make a list from a raw_input in python?

user3481478 picture user3481478 · Apr 12, 2014 · Viewed 63.9k times · Source

So I am taking raw_input as an input for some list.

x= raw_input()

Where I input 1 2 3 4 How will I convert it into a list of integers if I am inputting only numbers?

Answer

shaktimaan picture shaktimaan · Apr 12, 2014

Like this:

string_input = raw_input()
input_list = string_input.split() #splits the input string on spaces
# process string elements in the list and make them integers
input_list = [int(a) for a in input_list]