[sapug] Simple Sequence Question
Daryl Tester
Daryl.Tester at iocane.com.au
Tue Jun 20 10:33:04 CEST 2006
Darryl Ross wrote:
> 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]
Well, it's looping and slicing:
s = '1234567812345678'
t, s = s[:4], s[4:]
while s:
t, s = t + ':' + s[:4], s[4:]
--
Regards,
Daryl Tester, IOCANE Pty. Ltd.
More information about the sapug
mailing list