Unique characters: Difference between revisions

Content added Content deleted
Line 949: Line 949:
for i=1, string.len(str) do
for i=1, string.len(str) do
local char = string.sub(str,i,i)
local char = string.sub(str,i,i)
map[char] = true -- store unique only
if map[char] == nil then
map[char] = true
else
map[char] = false
end
end
end
local list = {}
local list = {}
for char, bool in pairs (map) do
for char, bool in pairs (map) do
if bool then
table.insert (list, char) -- all unique in list
table.insert (list, char)
end
end
end
table.sort (list) -- sorted list
table.sort (list)
print (unpack (list))
print (unpack (list))
end
end</lang>
{{out}}<pre>1 5 a b c
</lang>
6 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}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==