python - Taking dynamic number of inputs from the same line -


how can take dynamic number of inputs same line? example, if n number of inputs, , if n = 3, how can take in 3 different inputs, separated spaces, , store them 3 different variables?

now, know how take inputs same line, provided know value of n beforehand. using following code if number of inputs 3, , assign them variables a, b , c respectively:

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

however, can't seem figure out how use code assigning dynamic number of inputs equal number of variables.

what storing items in list , processing them individually?

list_of_input = map(int,raw_input().split())  print "you input:" i,input_val in enumerate(list_of_input):     print "item %d: %d:" % (i, input_val)      if input_val < 5:         pass   # items     elif input_val > 10:         pass   # else other items     else:          pass   # etc 

and if dead set on having "unique" string variable names each input (even though same behavior numeric list index more robust, general, faster , simpler following suggestion):

var_names = "abcdefghijklmnopqrstuvwxyz" named_lookup = dict(zip(var_names, list_of_input))  print named_lookup["c"] 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -