Back
What's the one-liner for the below code?
for k,v in d2.items(): if d1.get(k,0) < v: return Falsereturn True
for k,v in d2.items():
if d1.get(k,0) < v:
return False
return True
I tried this but it's invalid syntax.
return False if d1.get(k,0)<v for k,v in d2.items() else True
Why?
Use any or all:
return not any(d1.get(k, 0) < v for k, v in d2.items())
or
return all(d1.get(k, 0) >= v for k, v in d2.items())
Do check out Data Science with Python course which helps you understand from scratch.
30.9k questions
32.9k answers
500 comments
665 users