How to use dictionary from other funtion to another

Advertisements

Im a beginner and please help, what exactly i need to use to next one:
i want to use dictionary data with name & color from init_dict to show_dict and print it all

from printing_functions_1 import init_dict as pr
from printing_functions_1 import show_dict as sd

pr('DArya', 'Total Black', another_color = 'purple', lovely_film = 'mystic')
sd(another_color = 'purple', lovely_film = 'mystic')

def init_dict(name, color, **argv):
    argv['Name'] = name
    argv['Color'] = color


def show_dict(**argv):
    for key, value in argv.items():
        print(key, value)

expect somethinglike this from output with show_dict:

another_color purple
lovely_film mystic
Name DArya
Color Total Black

>Solution :

Here’s a corrected version of the code that would produce the desired output:

def init_dict(name, color, **argv):
    argv['Name'] = name
    argv['Color'] = color
    return argv

def show_dict(d):
    for key, value in d.items():
        print(key, value)

d = init_dict('DArya', 'Total Black', another_color='purple', lovely_film='mystic')
show_dict(d)

Output:

another_color purple
lovely_film mystic
Name DArya
Color Total Black

Leave a ReplyCancel reply