Oct-25-2020, 11:54 PM
I can't figure out how to make functions for the dictionary in the dictionary, how to pass arguments if there is a string. It would be nice if someone could write at least one function, then I would understand the progress of the task and I think I could finish the rest. Thanks in advance!
Here is the code for which I need to do all these tasks:
my_dict={'1':{'surname':'Musk', 'name':'Elon', 'gender': 'm','growth':183},
'2':{'surname':'Holmes', 'name':'Enola', 'gender': 'f','growth':175},
'3':{'surname':'Brown', 'name':'Lilly', 'gender': 'f','growth':178},
'4':{'surname':'Lothbrok', 'name':'Ragnar', 'gender': 'm','growth':189},
'5':{'surname':'Smith', 'name':'Adreana', 'gender': 'f','growth':173},
'6':{'surname':'Moon', 'name':'Larry', 'gender': 'm','growth':184}}
for key in my_dict:
if my_dict[key]['gender']=='m':
male_max_growth = max(my_dict.keys(), key=(lambda key: my_dict[key]['growth']))
tallest_guy=my_dict[male_max_growth]['surname']
print('The tallest guy: ', tallest_guy)
for key in my_dict:
if my_dict[key]['gender']=='f':
female_min_growth = min(my_dict.keys(), key=(lambda key: my_dict[key]['growth']))
lowest_girl=my_dict[female_min_growth]['surname']
print('The lowest girl: ', lowest_girl)
for key in my_dict:
sorted_key=sorted(my_dict.keys(), key=(lambda key: my_dict[key]['surname']))
for i in sorted_key:
student1=sorted_key[0]
student2=sorted_key[1]
student3=sorted_key[2]
student4=sorted_key[3]
student5=sorted_key[4]
student6=sorted_key[5]
print('Information about sorted students: ')
print(my_dict[student1])
print(my_dict[student2])
print(my_dict[student3])
print(my_dict[student4])
print(my_dict[student5])
print(my_dict[student6])
print('The correct order: ')
print(sorted_key)
Here is the code for which I need to do all these tasks:
my_dict={'1':{'surname':'Musk', 'name':'Elon', 'gender': 'm','growth':183},
'2':{'surname':'Holmes', 'name':'Enola', 'gender': 'f','growth':175},
'3':{'surname':'Brown', 'name':'Lilly', 'gender': 'f','growth':178},
'4':{'surname':'Lothbrok', 'name':'Ragnar', 'gender': 'm','growth':189},
'5':{'surname':'Smith', 'name':'Adreana', 'gender': 'f','growth':173},
'6':{'surname':'Moon', 'name':'Larry', 'gender': 'm','growth':184}}
for key in my_dict:
if my_dict[key]['gender']=='m':
male_max_growth = max(my_dict.keys(), key=(lambda key: my_dict[key]['growth']))
tallest_guy=my_dict[male_max_growth]['surname']
print('The tallest guy: ', tallest_guy)
for key in my_dict:
if my_dict[key]['gender']=='f':
female_min_growth = min(my_dict.keys(), key=(lambda key: my_dict[key]['growth']))
lowest_girl=my_dict[female_min_growth]['surname']
print('The lowest girl: ', lowest_girl)
for key in my_dict:
sorted_key=sorted(my_dict.keys(), key=(lambda key: my_dict[key]['surname']))
for i in sorted_key:
student1=sorted_key[0]
student2=sorted_key[1]
student3=sorted_key[2]
student4=sorted_key[3]
student5=sorted_key[4]
student6=sorted_key[5]
print('Information about sorted students: ')
print(my_dict[student1])
print(my_dict[student2])
print(my_dict[student3])
print(my_dict[student4])
print(my_dict[student5])
print(my_dict[student6])
print('The correct order: ')
print(sorted_key)