For some reason, I realized only today that in Python, dict unpacking works just like tuple unpacking.

>>> def fn1(x=1, y=2):
...   print x, y
...
>>> d = {'x':'hello', 'y':'world'}
>>> fn1(**d)
hello world
>>>

Comments

I think you start writing hello world programs like this once you have reached the 9th level of programming!

And what's on levels 1 to 8?!

I have given it some thought and although I instinctively know that what you wrote above comes in level 9, I haven't a good idea of what comes before. Here is a try:

Level 1: Search google for 'how to write hello world in python' Level 2: print 'hello world' Level 3: print u'hello world' Level 4: def hello(): print 'hello world' hello() Level 5: def hello(): print 'hello world' if name == "main": hello() Level 6: class hello: def hello(self): print 'hello world' hello().hello() Level 7: This would probably involve the following: 1. webservice that echos whatever you send it 2. Invoking the webservice with the networking library 3. Getting the output and printing it Level 8: This would probably involve writing a hello function in C, compiling it to a library, loading the library from python and calling the function.

OK, the formatting got totally screwed. If it is possible for you to edit and fix the formatting, please feel free.

haha.. don't forget that I've already written about level 7 in various forms on my blog :-)


Markdown formatting supported