Homework 3 - 3.4 Dictionaries, where is my error?
I'm trying to solve the problem with a dictionary containing names and ages and I don't see why my code is wrong.
new = combine_lists(NAMES, AGES) #the function creates a dictionary
for item in new:
if new[item] == x:
For each name I check whether the value (=age) is say 18 or any other age and actually it should return all names with this age, but I only get one key even if there are more people with this age. What am I doing wrong? Thanks
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
You're returning from people instead of accumulating, in say a list, your matches.
I solved the problem using the function below. The program returns 'True' to all test cases, but it returns 'False' to the final test case, when it should return an empty list ! I'm not sure where i'm going wrong!?
""" takes a value and returns dictionary keys of that value"""
di = (combine_lists(names,ages))
for na,a in di.iteritems():
if a == n:
for look in li:
print 'd' in people(18) and 'c' in people(18)
print 'e' in people(19) and 'h' in people(19) and\
'i'in people(19) and 'j' in people(19) and 'l' in people(19)
print 'a' in people(20) and 'f' in people(20) and 'g'in people(20)
print people(21) == ['b']
print people(22) == ['k']
print people(23) ==