Hi, Rustom, On Tue, Jan 14, 2014 at 2:16 AM, Rustom Mody <rustompm...@gmail.com> wrote: > On Tuesday, January 14, 2014 3:32:24 PM UTC+5:30, Igor Korot wrote: >> Hi, Rustom, > >> On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody wrote: >> > On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote: >> >> What if I want field 2 and field 3? ("seq 200" and "length 30") >> > Wee you did say: >> >> I'm interesred in only one element, so why should care about everything >> >> else? >> > So its not clear what you want! > >> Sorry, I thought it would be easier to ask this way. Guess not. > >> I am actually looking for a way to get a result from split which is >> sliced the way I want. Like in my example above. >> I mean I can probably make more variable by creating a tuple, but why? >> What is the purpose if I want only couple elements out of split. >> Doing it Perl way does not help: > >> C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python >> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> test = "I,like,my,chocolate" >> >>> print test.split(',')[2,3] > > You want this? > >>>> test = "I,like,my,chocolate" >>>> test.split(',') > ['I', 'like', 'my', 'chocolate'] >>>> test.split(',')[2:4] > ['my', 'chocolate']
Yup, thats it. Now 2 and 4 - it's a starting point and ending point, right? Thank you. > > >> Well is there a Python way to do what I want? > > > Well I for one still dont get what you want!! > > Heres a python one-liner using regexps >>>> r=r'(.*) +> +(.*):.*length (\d*)' >>>> re.findall(r,data) > [('192.168.1.6', '192.168.1.7', '30')] > > Note: I am NOT suggesting you use regexps. Just that they will do what you > want if you are so inclined > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list