Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] setdefault's second argument

Wolfgang Lippparagate at gmx.net
Tue Aug 30 20:37:10 CEST 2005


On Tue, 30 Aug 2005 18:14:55 +0200, Tim Peters <tim.peters at gmail.com>  wrote:>>>> d = {}>>>> d.setdefault(666)>>>> d> {666: None}>> just doesn't seem useful.  In fact, it's so silly that someone calling> setdefault with just one arg seems far more likely to have a bug in> their code than to get an outcome they actually wanted.  Haven't foundreminds me of dict.get()... i think in both cases being explicit::     beast = d.setdefault( 666, None )     beast = d.get( 666, None )just reads better, allthemore since at least in my code what comesnext is invariably a test 'if beast is None:...'. so     beast = d.setdefault( 666 )     if beast is None:         ...and     beast = d.get( 666 )     if beast is None:         ...a shorter but a tad too implicit for my feeling._wolf


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp