On Thu, Sep 10, 2009 at 11:36 AM, AJAskey <aske...@gmail.com> wrote: > New to Python. I can solve the problem in perl by using "split()" to > an array. Can't figure it out in Python. > > I'm reading variable lines of text. I want to use the first number I > find. The problem is the lines are variable. > > Input example: > this is a number: 1 > here are some numbers 1 2 3 4 > > In both lines I am only interested in the "1". I can't figure out how > to use "split()" as it appears to make me know how many space > separated "words" are in the line. I do not know this. > > I use: a,b,c,e = split() to get the first line in the example. The > second line causes a runtime exception. Can I use "split" for this? > Is there another simple way to break the "words" into an array that I > can loop over? > > >>> line = "here are some numbers 1 2 3 4" >>> a = line.split() >>> a ['here', 'are', 'some', 'numbers', '1', '2', '3', '4'] >>> #Python 3 only ... a,b,c,d,*e = line.split() >>> e ['1', '2', '3', '4']
> Thanks. > Andy > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list