Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use dictionary from other funtion to another

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading