nested tuple slice
dimitri pater
dimitri.pater at gmail.com
Tue Apr 12 18:23:11 EDT 2005
Thanks,
I have been trying this:
tuple = (('goat', 90, 100), ('cat', 80, 80), ('platypus', 60, 800))
index = 0
newtuple = ()
for item in tuple:
newtuple = newtuple + tuple[index][0:2]
index += 1
print newtuple
but it returns:
('goat', 90, 'cat', 80, 'platypus', 60)
which is no longer nested, and I need a nested tuple
Dimitri
On Apr 12, 2005 11:53 PM, Leeds, Mark <mleeds at mlp.com> wrote:
>
> maybe list(tuple)[0:2])) will
>
> get you what you
>
> want but I don't know how to
>
> change it back to a tuple.
>
> I'm just starting out but
>
> I would be interested also.
>
> mark
>
> -----Original Message-----
> *From:* python-list-bounces+mleeds=mlp.com at python.org [mailto:
> python-list-bounces+mleeds=mlp.com at python.org] *On Behalf Of *dimitri
> pater
> *Sent:* Tuesday, April 12, 2005 5:49 PM
> *To:* python-list at python.org
> *Subject:* nested tuple slice
>
> hello!
>
> I want to change a nested tuple like:
> tuple = (('goat', 90, 100), ('cat', 80, 80), ('platypus', 60, 800))
> into:
> tuple = (('goat', 90), ('cat', 80), ('platypus', 60))
>
> in other words, slice the first elements of every index
>
> Any ideas on how to do this in an elegant, pythonic way?
>
> Best regards,
> Dimitri
>
>
>
--
Please visit dimitri's website: www.serpia.com <http://www.serpia.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050413/6a920f56/attachment.html>
More information about the Python-list
mailing list