You can replace take_left_padding and take_right_padding by using a regular 
expression:

import re
intersperse_pat = re.compile('([^0-9]*)([0-9]*)(.*)')

def intersperse(string, counts, separator=''):
    """

    See the asserts below for examples.

    """
    # extract the first group of digits
    left, rest, right = intersperse_pat.match(string).groups()
    def reverse(s): return s[::-1]
    splits = split(reverse(rest), counts)
    res = separator.join(map(reverse, reverse(splits)))
    return left + res + right, len(splits) > 0 and len(splits) -1 or 0

Note that you can also avoid the multiple reversal of the strings, and perform 
the splits right-to-left, using negative indexes.  This would be more direct, 
but less reusable...

-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-format-lang-fix-vmt/+merge/61078
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/trunk-format-lang-fix-vmt.

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-web
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-web
More help   : https://help.launchpad.net/ListHelp

Reply via email to