Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Deduplicate List Items
Construct a new list retaining only unique occurrences of elements.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Collections & Lists). Copy the parameterized template or run the self-contained example.
- 1Category: Collections & Lists
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
to dedupeList items
result are empty
for each item in items
if not result contains item
add item to result
.
.
return result
.
to dedupeList items
result are empty
for each item in items
if not result contains item
add item to result
.
.
return result
.
raw are
"cat"
"dog"
"cat"
"bird"
.
uniquePets is dedupeList raw
say "Unique count:" length of uniquePets
if length of uniquePets is not 3
fail with "dedupeList length mismatch: expected 3"
.
if not uniquePets contains "dog"
fail with "dedupeList missing expected item 'dog'"
.
Installation & Usage
otter snippet inspect list-deduplicate
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.