[sapug] Simple Sequence Question

Darryl Ross spam at afoyi.com
Tue Jun 20 09:47:43 CEST 2006


Hey All,

Got a rather simple question about formatting a string. Say I have a string:

s = '1234567812345678'

and I want to format it like:

t = '1234:5678:1234:5678'

Is there a simple slicing operation? Or do I need to do something like:

t = ''
for i in xrange(len(s)):
  if not i == 0 and i % 4 == 0:
    t += ':'
  t += s[i]

Regards
Darryl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://mail.python.org/pipermail/sapug/attachments/20060620/8ff6186f/attachment.pgp 


More information about the sapug mailing list