The pythonic approach

Timo Virkkala a at a.invalid
Wed Sep 15 11:53:18 EDT 2004


Peter Hansen wrote:
> Timo Virkkala wrote:
> 
>> def thisReallyWorks(x):
>>     if x == "6$":
>>         return "$10 000"
>>     else:
>>         return x
>>
>> # or maybe
>>
>> investments = {"6$": "$10 000"}
>> def thisReallyWorks(x):
>>     return investments.get(x, x)
> 
> I really hope this is a contrived example, because if
> I ever saw something like this in real code I'd barf.
[snip]

It was, very contrived. I just like writing (wannabe) funny replies to 
spams... :) The idea in the second one was to be extensible. Yes, the dict 
should be defined elsewhere, and yes, inline .get is (usually) better than 
hiding it in a function.

Maybe I should just write real code and not bother with nonsense :)

-- 
Timo "WT" Virkkala

   "In the battle between you and the world, bet on the world."



More information about the Python-list mailing list