Results for “Slices & collections”
Small, practical examples. Search by task or narrow things down below.
Find values shared by two collections
Python: Use set intersection and sort the result for deterministic display.
Python✓ Tested
Flatten nested collections
Java: Use flatMap to concatenate nested Java lists into one stream.
Java✓ Tested
Flatten nested collections
Flatten nested collections in a complete Rust program using the standard library.
Rust✓ Tested
Flatten nested collections with SelectMany
C#: Concatenate the items from several sequences into one sequence.
C#✓ Tested
Generate combinations across two collections
Python: Use product for a Cartesian product; this differs from selecting combinations within one collection.
Python✓ Tested
Join string slices
Join string slices in a complete Rust program using the standard library.
Rust✓ Tested
Partition values into two collections
Partition values into two collections in a complete Rust program using the standard library.
Rust✓ Tested
Add a dictionary entry only if absent
C#: TryAdd reports a duplicate key without replacing its existing value.
C#✓ Tested
Append several values to a vector
Append several values to a vector in a complete Rust program using the standard library.
Rust✓ Tested
Apply classes from explicit Boolean state
jQuery: The second toggleClass argument applies a known state consistently.
jQuery✓ Tested
Build an object from key-value entries
JavaScript: Object.fromEntries converts an iterable of pairs into ordinary own properties.
JavaScript✓ Tested
Build an object from key-value entries
TypeScript: Object.fromEntries converts an iterable of pairs into ordinary own properties.
TypeScript✓ Tested