Results for “key”
Small, practical examples. Search by task or narrow things down below.
Find the insertion position for a sorted value
C++: lower_bound returns the first position whose value is not less than the search key.
C++✓ Tested
Get the latest row in each group
Select one ordered row per key with DISTINCT ON.
DISTINCT ON✓ Tested
Group records into map entries
JavaScript: Initialize an array for a missing Map key before appending its values.
JavaScript✓ Tested
Group records into map entries
TypeScript: Initialize an array for a missing Map key before appending its values.
TypeScript✓ Tested
Group strings by their length
Java: Choose a TreeMap supplier when group keys must have deterministic order.
Java✓ Tested
Include zero counts for missing relationships
SQL: Count the non-null child key after a left join so a missing relationship produces zero.
SQL✓ Tested
Include zero counts for missing relationships
SQL Server: Count the non-null child key after a left join so a missing relationship produces zero.
SQL Server✓ Tested
Include zero counts for missing relationships
Postgres: Count the non-null child key after a left join so a missing relationship produces zero.
Postgres✓ Tested
Include zero counts for missing relationships
SQLite: Count the non-null child key after a left join so a missing relationship produces zero.
SQLite✓ Tested
Initialize a map entry only when absent
Java: Use computeIfAbsent when creating a collection for a new key.
Java✓ Tested
Invert a dictionary with unique values
Python: Swap keys and values when the values are hashable and unique.
Python✓ Tested
Join related rows from two tables
SQL: Match a category key to its display label with an explicit join condition.
SQL✓ Tested