Search code examples
pythonpython-3.xdictionary-comprehension

Need solution For Dictionary comprehension


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() }