FIND YOUR NEXT FEW LINES

Results for “dictionary”

Small, practical examples. Search by task or narrow things down below.

20 snippets foundClear filters
C#Collections & data structures

Add a dictionary entry only if absent

C#: TryAdd reports a duplicate key without replacing its existing value.

C#✓ Tested
C#JSON & binary formats

Deserialize a JSON object into a dictionary

C#: Specify the value type expected from a known JSON shape.

C#✓ Tested
PythonMappings & sets

Invert a dictionary with unique values

Python: Swap keys and values when the values are hashable and unique.

Python✓ Tested
C#Collections

Look up a dictionary value

Use TryGetValue for a C# dictionary lookup with a fallback.

C#✓ Tested
PythonMappings & sets

Read an optional dictionary key

Python: Use get with a fallback while leaving the dictionary unchanged.

Python✓ Tested
PythonMappings & sets

Remove and return a dictionary entry

Python: Use pop with a default when a missing entry is an expected condition.

Python✓ Tested
TypeScriptCollections & records

Type a dictionary with Record

Limit a lookup table to a known set of keys.

Record✓ Tested
C#Collections & data structures

Use case-insensitive dictionary keys

C#: Choose an ordinal comparer when case-insensitive keys represent identifiers.

C#✓ Tested
TypeScriptCollections & records

Count words using a Map

Update a keyed counter without losing its value type.

Map✓ Tested
Bash ScriptsFunctions & arguments

Look up values in an associative array

Use named keys for a small in-memory configuration table.

dictionary✓ Tested
PythonCollections

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
PythonJSON & CSV

Parse a JSON string

Convert a JSON string into a Python dictionary and read values by key.

json✓ Tested