Splitting a string

Shashwat Anand anand.shashwat at gmail.com
Fri Apr 2 06:21:44 EDT 2010


>>> s = 'si_pos_99_rep_1_0.ita'
>>> res = tuple(re.split(r'(\d+)', s))
>>> res
('si_pos_', '99', '_rep_', '1', '_', '0', '.ita')
>>>


On Fri, Apr 2, 2010 at 3:42 PM, Thomas Heller <theller at ctypes.org> wrote:

> Maybe I'm just lazy, but what is the fastest way to convert a string
> into a tuple containing character sequences and integer numbers, like this:
>
>
> 'si_pos_99_rep_1_0.ita'  -> ('si_pos_', 99, '_rep_', 1, '_', 0, '.ita')
>
> Thanks for ideas,
> Thomas
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100402/a4f27ffc/attachment-0001.html>


More information about the Python-list mailing list