Re: [Tutor] Splitting a number into even- and odd- numbered digits
by John Fouhy other posts by this author
Apr 19 2006 5:49PM messages near this date
Re: [Tutor] Splitting a number into even- and odd- numbered digits
|
[Tutor] Reqiest Centre - Adding New Call
On 20/04/06, Carroll, Barry <Barry.Carroll@[...].com> wrote:
> The following code fragment does the job but seems sort of brutish and inelegant to me:
>
> >>>>>>>
> >>> s = '987654321'
> >>> odd = ''
> >>> for c in s[::-2]:
> ... odd = c + odd
> ...
> >>>
String slicing will actually produce strings :-)
eg:
> >> s = '987654321'
> >> s1, s2 = s[::-2], s[-2::-2]
> >> s1
'13579'
> >> s2
'2468'
--
John.
_______________________________________________
Tutor maillist - Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Barry Carroll
Python
Barry Carroll
Barry Carroll
John Fouhy
|