Converting Python dict to kwargs?

teaforthecat picture teaforthecat · Apr 19, 2011 · Viewed 141.2k times · Source

I want to build a query for sunburnt(solr interface) using class inheritance and therefore adding key - value pairs together. The sunburnt interface takes keyword arguments. How can I transform a dict ({'type':'Event'}) into keyword arguments (type='Event')?

Answer

unutbu picture unutbu · Apr 19, 2011

Use the double-star (aka double-splat?) operator:

func(**{'type':'Event'})

is equivalent to

func(type='Event')