Home > Software engineering >  Need solution For Dictionary comprehension
Need solution For Dictionary comprehension

Time:06-27

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?

CodePudding user response:

Try this

f = { k: int(v * 0.7) for k, v in d.items() }
  • Related