Function Returning Dictionary and Set of Doubled Values

  • Share this:

Code introduction


Define a function that takes three arguments and returns a dictionary and a set. The keys of the dictionary are the indices of the arguments, and the values are twice the value of the arguments. The set contains the keys of the dictionary.


Technology Stack : Built-in functions, list comprehensions, dictionary comprehensions, sets

Code Type : Function

Code Difficulty : Intermediate


                
                    
def a_func(arg1, arg2, arg3):
    def b_func(arg):
        return arg * 2

    c_list = [arg1, arg2, arg3]
    d_dict = {i: b_func(c) for i, c in enumerate(c_list)}
    e_set = set(d_dict.keys())

    return d_dict, e_set