Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteTo select several keys into a new dictionary and silently omit keys that are missing, use a dictionary comprehension: selected = {k: d[k] for k in keys if k in d}. If you need values in a list or tuple instead, choose a lookup that matches how you want missing keys handled.
Choose the result you need
These examples use the same dictionary and requested keys:
d = {"name": "Ada", "age": 36, "city": "London"}
keys = ["name", "city", "country"]
| Goal | Expression | Result and missing-key behavior |
|---|---|---|
| New dictionary; skip absent keys | {k: d[k] for k in keys if k in d} |
{'name': 'Ada', 'city': 'London'}; absent keys are omitted. |
| List; provide a fallback | [d.get(k, None) for k in keys] |
['Ada', 'London', None]; replace None with another default if desired. |
| List; require all keys | [d[k] for k in keys] |
Returns values in requested-key order; raises KeyError if a key is absent. |
| Tuple; require all keys | itemgetter(*keys)(d) |
Returns a tuple; raises KeyError if a key is absent. |
Build a smaller dictionary
Use a comprehension when you want a new dictionary rather than just the values. This version follows the order of keys and ignores requested keys that are not in d:
selected = {k: d[k] for k in keys if k in d}
# {'name': 'Ada', 'city': 'London'}
Membership testing with k in d checks whether the key is present. The official Python 3.12 documentation for dictionary types describes membership, subscription, and get().
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
Return values in a list
Use a default for missing keys
Call get() for each requested key when a missing key should produce a fallback rather than an exception:
values = [d.get(k, None) for k in keys]
# ['Ada', 'London', None]
dict.get(key, default) returns the default when the key is absent. Choose a fallback that makes sense for your data; the default can be any value.
Rank #2
Raise an error if a key is absent
Use subscription when every requested key must exist:
values = [d[k] for k in keys]
# ['Ada', 'London']
The returned list follows the order of keys. If even one requested key is missing, subscription raises KeyError, which can help expose unexpected or incomplete input rather than quietly substituting a value.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesReturn a tuple with itemgetter
For a tuple of values when all keys are expected to exist, use itemgetter from the standard-library operator module:
from operator import itemgetter
values = itemgetter(*keys)(d)
# ('Ada', 'London', 'Paris' would require 'country' to exist)
With multiple item names, itemgetter returns a tuple. It uses item access, so an absent key raises KeyError; use the get() comprehension if missing keys need defaults. See the Python 3.13 operator documentation.
Select keys in dictionary order instead
If the set of desired keys matters but their requested order does not, iterate over the dictionary and test membership in a set:
wanted = {"name", "city"}
selected = {k: d[k] for k in d if k in wanted}
This builds the result in the dictionary’s key order, not the order of wanted. Dictionary iteration follows insertion order. To produce sorted keys instead, iterate over sorted(d) and apply the same membership test. The Python tutorial’s dictionary section documents key iteration and sorted-key examples.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Quick Recap
Best Value
Which approach should you use?
- Choose a dictionary comprehension when you need a subset dictionary.
- Choose
d.get(k, default)when absent keys should receive a fallback. - Choose
d[k]oritemgetter(*keys)(d)when all keys should exist and a missing key should raise an error. - Use the requested-key sequence to control result order, or iterate over the dictionary when its key order should control the result.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




