New user's initial thoughts / criticisms of Python

Roy Smith roy at panix.com
Mon Nov 11 15:01:07 CET 2013


> On Saturday, November 9, 2013 10:30:26 AM UTC-6, rusi wrote:

> > print ( {"mon":"mondays suck",
> >          "tue":"at least it's not monday",
> >          "wed":"humpday"
> >         }.get(day_of_week,"its some other day")
> >       )

In article <8618d47d-518c-4f35-a879-57fad7525411 at googlegroups.com>,
 Rick Johnson <rantingrickjohnson at gmail.com> wrote:
> Proper code formatting can do WONDERS for readability!
> 
> d = {
>     "mon":"mondays suck",
>     "tue":"at least it's not monday",
>     "wed":"humpday"
>     }
> default = "some other day"
> target = "tue"
> print d.get(target, default)
> target = "blah"
> print d.get(target, default)

I agree that Rick's version is better than rusi's version, but possibly 
not for the the reason Rick thinks it is :-)  rusi's version has a 
"parsing surprise" in it.  As a human scans the code, the thought 
process goes something like this:

> > print ( {"mon":"mondays suck",

"OK, I'm going to print a dictionary"

> >          "tue":"at least it's not monday",

"Yeah, still looks like I'm printing a dictionary"

> >          "wed":"humpday"

"Yeah, more dictionary, this still makes sense, I'm just waiting to get 
to the and of the dictionary so I can print it"

> >         }.get(day_of_week,"its some other day")

"Oh, my!  I'm not printing a dictionary after all!  I'm doing a get() on 
it!"

> >       )

"Ugh, what's this close paren?  Does it terminate the get(), or the 
print()?  I need to go back and count open parens to make sure"



More information about the Python-list mailing list