Unique characters: Difference between revisions

Line 949:
for i=1, string.len(str) do
local char = string.sub(str,i,i)
if map[char] == true -- store uniquenil onlythen
map[char] = true
else
map[char] = false
end
end
local list = {}
for char, bool in pairs (map) do
if bool then
table.insert (list, char) -- all unique in list
end
end
table.sort (list) -- sorted list
print (unpack (list))
end</lang>
{{out}}<pre>1 5 a b c
</lang>
6 7 8 9 a s t
{{out}}<pre>
d f g z</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>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Anonymous user