0

I want to display output in terms of keys: values as:

dad:bob
Mom:lisa
brother : joe
& so on

But only values are shown in the output.

what changes should I make in this code to get the desired output?

d = dict(Dad='Bob', Mom='Lisa', Brother= 'joe')
def f2(Dad,Mom,Brother):
    print Dad,Mom,Brother
f2(**d)
flakes
  • 21,558
  • 8
  • 41
  • 88
user112647
  • 73
  • 1
  • 2
  • 4

1 Answers1

5

Use **kwargs for handling function keyword arguments:

d = dict(Dad='Bob', Mom='Lisa', Brother= 'joe')
def f2(**kwargs):
    for key, value in kwargs.iteritems():
        print '%s:%s' % (key, value)
f2(**d)

prints:

Dad:Bob
Brother:joe
Mom:Lisa

Also see:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195