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.
31k questions
32.8k answers
501 comments
693 users