In Python, is it possible to unpack a dict without passing it to a function?

47 views Asked by At

I have a dict

dict = {
   'key1': 'value1',
   'key2': 'value2' 
}

and would like to unpack it to

key1 = 'value1'
key2 = 'value2'

I know that if I do

def some_func(key1, key2):
    # do stuff with key1 and key2

and then call

some_func(**dict)

then in my function I will have access to those variables.

Is there a way to get these values out without having to call the function with the dict as an argument or requiring:

key1 = dict['key1']
key2 = dict['key2']
0

There are 0 answers