thanks brother
i mean how do i particularly assign (u = this)
                                    (y = is)....
in the strings up there. i have been able to split strings with any
character sign.



If i'm not wrong this is simple with RE:

In [1]: st  = 'this is a python coding group'

In [2]: import re

In [3]: re.compile( "(?P<first>.*) (?P<second>.*) (?P<t>.*) (?P<fo>.*) (?P<fi>.*) (?P<si>.*)" )
Out[3]: <_sre.SRE_Pattern object at 0x9e93ac0>

In [4]: rule = re.compile( "(?P<first>.*) (?P<second>.*) (?P<t>.*) (?P<fo>.*) (?P<fi>.*) (?P<si>.*)" )

In [5]: m  = rule.match( st )

In [6]: dir(m)
Out[6]:
['__copy__',  '__deepcopy__',
 'end',  'expand',
 'group',  'groupdict',
 'groups',  'span',  'start']

In [7]: m.groupdict().items()
Out[7]:
[('si', 'group'),
 ('second', 'is'),
 ('t', 'a'),
 ('fi', 'coding'),
 ('fo', 'python'),
 ('first', 'this')]

In [8]: dict(m.groupdict().items())
Out[8]:
{'fi': 'coding',
 'first': 'this',
 'fo': 'python',
 'second': 'is',
 'si': 'group',
 't': 'a'}



Glauco
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to