Results for “Collections & styling”
Small, practical examples. Search by task or narrow things down below.
Find values common to two collections
C#: Intersect returns distinct values shared by the inputs.
C#✓ Tested
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
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
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
Copy a slice without sharing storage
Copy a slice without sharing storage using a complete Go program with explicit sample inputs.
Go✓ Tested
Copy nested structured data independently
JavaScript: structuredClone creates an independent copy of supported structured values.
JavaScript✓ Tested