-3

Trying to figure out what to change to get this to work. I want to print out the value of 'homework' Thanks!

dic1 = dict(tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
})
number = ['0','1','2']
def foo(dict_search):
    for key, value in dict_search.items() :
        if key == "homework":
            print ('homework',value)
    #dict_search[:] = dic1  # swap the slice around here

foo(dic1)
andrea.marangoni
  • 1,499
  • 8
  • 22
  • Why the `dict(tyler=`? Are you sure you know what that does? It looks like you just wanted the part in the braces. – user2357112 Dec 06 '13 at 02:00

1 Answers1

3

The easiest way to do what you're asking for is:

value = dic1["tyler"]["homework"]
print(value)

No need for your complicated function -- that use case is exactly what dicts are made for.

(for more info about how dictionaries work and what they're used for, please refer to the documentation: http://docs.python.org/2/library/stdtypes.html#dict)

Max Noel
  • 8,810
  • 1
  • 27
  • 35