Issue
This is the input:
d={"mango":50,"apple":100,"banana":70} # this is the input
This should be the output:
{"mango":35,"apple":70,"banana":49}
I tried this:
f = {i:int(i*0.7) for i in d}
How do I do this using dictionary compression only?
Solution
Try this
f = { k: int(v * 0.7) for k, v in d.items() }
Answered By - Max
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.