string in files

Glauco 00515879256 at
Tue Dec 30 11:53:17 CET 2008

> 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)
['__copy__',  '__deepcopy__',
  'end',  'expand',
  'group',  'groupdict',
  'groups',  'span',  'start']

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

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


More information about the Python-list mailing list