0% found this document useful (0 votes)
7 views

Python 1689719949

The document discusses different ways to create a new dictionary from an existing one that only includes key-value pairs where the value is a list of integers and the sum of the integers is greater than a threshold. It provides an example dictionary and threshold and the expected output dictionary. It then outlines three solutions to the problem and asks which solution is most performant.

Uploaded by

walteravelin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python 1689719949

The document discusses different ways to create a new dictionary from an existing one that only includes key-value pairs where the value is a list of integers and the sum of the integers is greater than a threshold. It provides an example dictionary and threshold and the expected output dictionary. It then outlines three solutions to the problem and asks which solution is most performant.

Uploaded by

walteravelin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Python

Coding
Problem Statement -
Given a dictionary with a set of keys and
values, how can you create a new dictionary
that only includes key-value pairs where the
value is a list of integers, and the sum of
the integers in the list is greater than a
certain threshold value?
Example -
Let's say we have the following
dictionary:

my_dict = {
"key1": [1, 2, 3],
"key2": [4, 5, 6],
"key3": "hello",
"key4": [7, 8, 9, 10]
}
And let's say our threshold value is 14.
We want to create a new dictionary
that only includes the key-value pairs
where the value is a list of integers and
the sum of those integers is greater
than 14.

The resulting dictionary should look


like this:
{
"key2": [4, 5, 6],
"key4": [7, 8, 9, 10]
}
Let's see different
ways to solve the
GIVEN problem
Solution 1 -
Using a for loop and if statement
Solution 2 -
Using a dictionary comprehension
Solution 3 -
Using filter() and lambda function
Which solution do
you feel is most
performant?
Keep
Learning

You might also like