python - Use of a function using **kwargs -


in exercise, have use **kwargs print arguments entered in function in alphabetical order.

here have now:

def afficher(**kwargs): if kwargs not none:     in kwargs:         print (i)  afficher(helpme=7,plz=10) 

returns:

plz helpme 

my concern is:

  • i'd them returned in alphabetical order
  • i'd them returned as:

    helpme = 7

    plz = 10

thanks in advance !

plain dictionaries not sorted, keys hashed , end stored accordingly.

in case can scan sorted keys of kwargs dictionary

for in sorted(kwargs): 

so code becomes

def afficher(**kwargs):     in sorted(kwargs):         print ('{}={}'.format(i,kwargs[i]))  afficher(helpme=7,plz=10) 

which produces

helpme=7 plz=10 

note: can see, have removed if, presume inserted check if keyword arguments passed function. in such case kwargs empty dictionary {}, not none, there no need prevent iteration.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -