Re: [Tutor] how to use int and split() simultaneously

2011-12-08 Thread Steven D'Aprano
शंतनू wrote: Using re module: === import re strNum = raw_input("enter numbers, separated by space: ") if re.search('[^\d ]', strNum): print('Invalid input') else: data = [int(x) for x in strNum.split()] print(data) This is not Perl, where everything is a nail that needs to be ham

Re: [Tutor] how to use int and split() simultaneously

2011-12-08 Thread शंतनू
On 08-Dec-2011, at 7:13 PM, Dario Lopez-Kästen wrote: > oh, yes, no top posting. See below. > > On Thu, Dec 8, 2011 at 1:33 PM, surya k wrote: > > This is something I am trying to do.. > Say, we are entering a string "1 2 3 4 5".so, I want to assign the numbers > directly as numbers. how can

Re: [Tutor] how to use int and split() simultaneously

2011-12-08 Thread Wayne Werner
On Thu, Dec 8, 2011 at 7:43 AM, Dario Lopez-Kästen wrote: > > > In that case a for loop with a try-except would better: > > strNum = raw_input("enter numbers, separated by space: ").split() > num_list = [] > > for token in strNum: > try: > num_list.append(int(token)) > except Valu

Re: [Tutor] how to use int and split() simultaneously

2011-12-08 Thread Dario Lopez-Kästen
oh, yes, no top posting. See below. On Thu, Dec 8, 2011 at 1:33 PM, surya k wrote: > > This is something I am trying to do.. > Say, we are entering a string "1 2 3 4 5".so, I want to assign the numbers > directly as numbers. how can I do it? > I could put that numbers as string but not as numbe