The things I don't know about python

| | No TrackBacks

Sometimes, I amaze myself with what I don't know. Here is a simple case: in python, you can pass a function a dictionary with keys with the same name as the function's arguments. For some reason, I thought this was only available when you identified keyword arguments.

>>> def foo(a, b) :
...     return a + b
...
>>> foo(2, 5)
7
>>> d = {'a':2, 'b':5}
>>> foo(**d)
7

No TrackBacks

TrackBack URL: http://www.iwebthereforeiam.com/cgi-bin/mt/mt-tb.cgi/1500

Leave a comment

Verification (needed to reduce spam):

Pages

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.32-en

About this Entry

This page contains a single entry by Hugh Brown published on June 5, 2009 11:29 AM.

Getting github working in Windows was the previous entry in this blog.

Another python thing I forget: dictionary construction is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.