Hi, Is there a way to change the key itself of a dictionary. For instance: items={'the first': [], 'the second': []} Now at a certain time I want to change the 'the first' in something else. Is there a 'rename' method? Sorry for being ingorant but I couldn't find in the documentation or on the net. I want to mimic the rename function in Zope. thanks, Henny
Henny van der Linde wrote:
Hi,
Is there a way to change the key itself of a dictionary.
For instance: items={'the first': [], 'the second': []}
Now at a certain time I want to change the 'the first' in something else. Is there a 'rename' method?
Sorry for being ingorant but I couldn't find in the documentation or on the net.
I want to mimic the rename function in Zope.
thanks,
Henny
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
you have to do it as Zope does, first create a new entry with the new key, and value , and then delete the old one. robert
items['NewKey'] = items['OldKey']; items.pop('OldKey') Henny van der Linde wrote:
Hi,
Is there a way to change the key itself of a dictionary.
For instance: items={'the first': [], 'the second': []}
Now at a certain time I want to change the 'the first' in something else. Is there a 'rename' method?
Sorry for being ingorant but I couldn't find in the documentation or on the net.
I want to mimic the rename function in Zope.
thanks,
Henny
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
.
-- Peter Bengtsson, http://www.peterbe.com
participants (4)
-
Chris Beaven -
Henny van der Linde -
Peter Bengtsson -
robert rottermann