Results for “dict”
Small, practical examples. Search by task or narrow things down below.
Add a dictionary entry only if absent
C#: TryAdd reports a duplicate key without replacing its existing value.
C#✓ Tested
Deserialize a JSON object into a dictionary
C#: Specify the value type expected from a known JSON shape.
C#✓ Tested
Invert a dictionary with unique values
Python: Swap keys and values when the values are hashable and unique.
Python✓ Tested
Look up a dictionary value
Use TryGetValue for a C# dictionary lookup with a fallback.
C#✓ Tested
Merge two dictionaries
Combine two dictionaries into a new dictionary. When a key appears in both inputs, the value from the second dictionary wins.
dictionary✓ Tested
Read an optional dictionary key
Python: Use get with a fallback while leaving the dictionary unchanged.
Python✓ Tested
Read CSV rows as dictionaries
Read a CSV file using its header row as dictionary keys, so each column can be accessed by name.
csv✓ Tested
Remove and return a dictionary entry
Python: Use pop with a default when a missing entry is an expected condition.
Python✓ Tested
Sort dictionaries by a value
Sort a list of dictionaries by a numeric field, leaving the original list unchanged.
sort✓ Tested
Type a dictionary with Record
Limit a lookup table to a known set of keys.
Record✓ Tested
Use case-insensitive dictionary keys
C#: Choose an ordinal comparer when case-insensitive keys represent identifiers.
C#✓ Tested
Write dictionaries to CSV
Write a list of dictionaries to a CSV file with a header row and a predictable column order.
csv✓ Tested