Function to Append Key-Value Pairs to a Dictionary

  • Share this:

Code introduction


Define a function that takes three arguments, the first argument initializes an empty dictionary, the second argument adds key-value pairs to the dictionary, and the third argument receives and prints the dictionary content.


Technology Stack : Dictionary

Code Type : Dictionary operation

Code Difficulty : Intermediate


                
                    
def append_to_dict(dict_obj, key, value):
    dict_obj[key] = value

def xxx(arg1, arg2):
    data = {}
    append_to_dict(data, 'a', arg1)
    append_to_dict(data, 'b', arg2)
    return data                
              
Tags: