#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Complete newbie question about searching dictionaries


    Hi, I started using python 2.7 last week, so am (as yet) utterly hopeless. I'm trying to define a function to search a dictionary of exam results, and return an answer for who got a result above 70. Could anyone possibly help me with my code? Thanks!

    marks={"John":45,"Suzy":46,"Edward":75,"Mike":66}
    def who_got_above_seventy(x):
    for p in x:
    if p>=70:
    print p

    Thanks!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Code:
    marks={"John":45,"Suzy":46,"Edward":75,"Mike":66}
    
    def who_got_above_seventy(x):
        for (name,score) in x.items():
            if score>=70:
                print(name)
    
    who_got_above_seventy(marks)
    Read the documents docs.python.org about dictionary methods.

    In the interpreter use
    >>> help(dict())
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo