On Feb 14, 1:08 pm, "amadain" <[EMAIL PROTECTED]> wrote: > I was wondering if there was a nicer way to swap the first 2 > characters in a string with the 4th and 5th characters other than: > > darr=list("010203040506") > aarr=darr[:2] > barr=darr[4:6] > darr[:2]=barr > darr[4:6]=aarr > result="".join(darr) > > The above code works fine but I was wondering if anybody had another > way of doing this?
Assuming the string length is always at least 5: def swap(s): return '%s%s%s%s' % (s[3:6], s[2:3], s[:2], s[6:]) -- http://mail.python.org/mailman/listinfo/python-list