On Sat, Jan 24, 2009 at 5:31 PM, <pyt...@bdurham.com> wrote: > Is there a way to slice a string with a tuple without unpacking the tuple? > > >>> myString = "111-222-333-444" > >>> myString[ 4: 7 ] > '222' > > Is there some way I could perform an identical slicing operation with a > tuple like ( 4, 7 ) without having to unpack the tuple? > > >>> myTuple = ( 4, 7 ) > > Thanks! > Malcolm >
1) What's wrong with unpacking the tuple? 2) Use the built-in slice. >>> myString = "111-222-333-444" >>> myTuple = (4,7) >>> mySlice = slice(*myTuple) >>> myString[mySlice] '222'
-- http://mail.python.org/mailman/listinfo/python-list