0

Let's say I have one dictionary with multiple keys but I just want to get the key and value of one of them and create a new dictionary with just that key and value (I don't need to pop or remove old values from the old dictionary).

How can I do it?

dictionary2 = dictionary1["expectedkey"]

This code just gives me the key value but I'm trying just to create a new dictionary with both key and value. I know I can always do it manually like this:

dictionary2 = {"expectedkey": dictionary1["expectedkey"]}

Just I wonder if there is a more straightforward way to do it as I just started with Python a couple of weeks ago and I'm quite sure there sould be a more simple way to do it.

Thanks!

Pcsl
  • 128
  • 9

0 Answers0