The Artima Developer Community
Sponsored Link

Python Buzz Forum
getdefault method for python dictionary

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Baiju M

Posts: 225
Nickname: baijum81
Registered: Aug, 2004

Baiju M is a new user
getdefault method for python dictionary Posted: Sep 2, 2005 1:52 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Baiju M.
Original Post: getdefault method for python dictionary
Feed Title: Programming life without Python(?)
Feed URL: http://baijum81.livejournal.com/data/rss
Feed Description: Programming life without Python(?)
Latest Python Buzz Posts
Latest Python Buzz Posts by Baiju M
Latest Posts From Programming life without Python(?)

Advertisement
In this blog:

http://blogs.nuxeo.com/sections/blogs/ruslan_spivak/2005_09_01_btrees-setdefault

Blogger says that Python's dictionary method, 'setdefault' without explicit default
is confusing and useless. Now I think there should be a 'getdefault' method
which also requires two explicit arguments, it will return explicit default
if no key exists.

Here is an example:

>>> d = {1: None}
>>> print d.getdefault(1, 'Hi')
None
>>> print d.getdefault(2, 'Hi')
'Hi'

Hmm.. there is already a 'get' method. If we have 'getdefault'
then 'get' can be deprecated, Here is the reason:

>>> d = {1: None}
>>> print d.get(1)
None
>>> print d.get(2)
None

See, here I didn't thought abount any use cases.

Read: getdefault method for python dictionary

Topic: Java Meetup next week Previous Topic   Next Topic Topic: All NZ phone lines will be VOIP in seven years

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use