Skip to content
Advertisement

How to drop pairs in dict

I want to drop value pairs in a dictionary if the first element contains a certain string (time or session), but keep the remaining pairs (word and group). dic1 is the one I have and dic2 is the one I would like.

I have written a one liner that removes the entire value element but thats not really what I want…I wonder where I am going wrong.

JavaScript

Advertisement

Answer

The unwanted keys are inside x here:

JavaScript

You need one more dict comprehension inside your comprehension:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement