On Thursday, February 23, 2012 2:27:44 AM UTC-5, Mchurch wrote:
**{'%s%s' % (Keyword, n): checked})
Anthony, can you explain it better? It's something that I would like
to understand very well.
'%s%s' % (Keyword, n) is Python string formatting -- if Keyword is "hello" and n is 5, it will produce the string "hello5". Now, suppose "checked" is a boolean value equal to True -- then the above will produce the following dictionary:
{hello5: True}
In Python, you can pass a dictionary to a function and precede it with **, and that is equivalent to passing each item in the dictionary to the function as a separate keyword argument. So,
update(**{hello5: True})
is equivalent to
update(hello5=True)
Of course, the "hello5" is generated dynamically, so we can't use the latter syntax, but we can construct a dictionary with a dynamically generated key, which enables us to use the former syntax.
Anthony