incremental count between two values on the same line in a list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davidgol
    New Member
    • Mar 2012
    • 1

    incremental count between two values on the same line in a list

    Hi All, newbie alert!
    Just getting into this so if somebody could help I would be most grateful.

    I have a list that could be hundreds of lines long containg a table with entries like this ...

    text45677text82
    text51234text35
    text312789text853


    "text"cound be various characters, obd, scd, sc, qw etc ...

    I want to create another list would give me the increments between the numbers and align it with the associated field from the original list.

    For instance line 1 would bring back the following ..

    text45677 is in text45677text82
    text45678 is in text45677text82
    text45679 is in text45677text82
    text45680 is in text45677text82
    text45681 is in text45677text82
    text45682 is in text45677text82

    line 2 ...

    text51234 is in text51234text35
    text51235 is in text51234text35

    line 3 ...

    text[B]312789[B] is in text312789text853
    text[B]312790[B] is in text312789text853
    ....
    ....
    text[B]312852[B] is in text312789text853
    text[B]312853[B] is in text312789text853

    Also can anybody recomend a decent Python book to get my learning off to a good start?

    Thanks
    Dave
  • Smygis
    New Member
    • Jun 2007
    • 126

    #2
    Well to start of I think this is best solved with regular expressions.

    Code:
    >>> import re
    >>> s = "text45677text82"
    >>> rxp = re.compile("[A-Za-z]")
    >>> re.split(rxp,s)
    ['', '', '', '', '45677', '', '', '', '82']
    >>>
    But it seems like you don't even program in python. I think I liked http://www.greenteapress.com/thinkpy...inkpython.html when i was learning.

    Comment

    Working...