Terry: > -----Original Message----- > Date: Thu, 20 Apr 2006 10:14:23 -0700 (PDT) > From: Terry Carroll <[EMAIL PROTECTED]> > Subject: Re: [Tutor] FW: Splitting a number into even- and odd- > numbered digits > To: tutor@python.org > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: TEXT/PLAIN; charset=US-ASCII > <<snip>> > > > > I could not find a way to include these requirements in a single, simple > > expression. > > I really liked John Fouhy's approach, or at least a variation of it: > > >>> def odd_even(s): > ... ''' > ... Returns a tuple of two strings taken from s. The first string is > ... the odd-numbered characters (counting from the right), and the > ... second is the even-numbered characters. > ... ''' > ... return (s[::-2][::-1], s[-2::-2][::-1]) > ... > >>> odd_even("1234567") > ('1357', '246') > >>> odd_even("2345") > ('35', '24') > >>> odd_even("1") > ('1', '') > >>> > > John's original solution returned values with the digits in reverse > order; but that's easily changed by reslicing each string with [::-1].
By golly you're right! That is a very slick solution. It didn't occur to me to re-reverse the strings like that. Thanks to both you and John. Regards, Barry [EMAIL PROTECTED] 541-302-1107 ________________________ We who cut mere stones must always be envisioning cathedrals. -Quarry worker's creed _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor