Unique characters: Difference between revisions

(Added 11l)
Line 938:
['1', '5', '6', 'b', 'g', 's', 't', 'z']
1.010 μs (14 allocations: 1.05 KiB)
</pre>
 
 
=={{header|Lua}}==
<lang Lua>local strings = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}
unpack = unpack or table.unpack -- compatibility for all Lua versions
 
for i, str in ipairs (strings) do
local map = {}
for i=1, string.len(str) do
local char = string.sub(str,i,i)
map[char] = true -- store unique only
end
local list = {}
for char, bool in pairs (map) do
table.insert (list, char) -- all unique in list
end
table.sort (list) -- sorted list
print (unpack (list))
end
</lang>
{{out}}<pre>
1 2 3 5 a b c d e f
6 7 8 9 a s t
c d f g x y z
</pre>
 
Anonymous user