I haven't taken python in a long time and am a bit rusty but for the first question I'm taking a dictionary and need to intersect it returning the key and the value. So for example, I'm entering
a = {1:'a1', 2.5:'a2', 4:'a3'}
b = {1:'a1', 3:'a2', 5:'a4'}
If I enter c = intersect(a,b)
, I want it to return {1:'a1'}
, but I only get back {'a1'}
.
My code so far is:
def intersect(a, b):
for i in a:
if j in b:
if a[i]==b[i]:
return ({i})
else:
return {}
{k: v for (k, v) in a.items() if k in b}
? – Kristelkristenintersect
code testsj
but never assigns it anything. – Dearrdict.items()
ordict.values()
. – Copro