Hash from two arrays: Difference between revisions

(Added XPL0 example.)
 
(4 intermediate revisions by 2 users not shown)
Line 1,303:
=={{header|langur}}==
=== the easy way ===
<syntaxhighlight lang="langur">writeln(hash toHash wfw/a b c d/, [1, 2, 3, 4]</syntaxhighlight>)
</syntaxhighlight>
 
Note that wfw/a b c d/ is a semantic convenience equivalent to ["a", "b", "c", "d"].
 
=== a longer way ===
Using the append operator would silently overwrite hash values for matching keys, but the more() function will not.
<syntaxhighlight lang="langur">val .new = foldfrom(
ffn(.hash, .key, .value) more .hash, h{.key: .value},
h{}hash(), wfw/a b c d/, [1, 2, 3, 4],
)
 
Line 1,317 ⟶ 1,318:
 
{{out}}
<pre>h{"d": 4, "a": 1, "b": 2, "c": 3}</pre>
 
=={{header|Lasso}}==
Line 2,722 ⟶ 2,723:
6
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">data "1", "one", "2", "two", "3", "three", "4", "four", "5", "five"
 
dim keys$(5), values$(5)
dim hash$(5)
 
for i = 1 to arraysize(keys$(), 1)
read a$, b$
keys$(i) = a$
values$(i) = b$
next i
 
for i = 1 to arraysize(values$(), 1)
temp = val(keys$(i))
hash$(temp) = values$(i)
next i
 
for i = 1 to arraysize(hash$(), 1)
print keys$(i), " ", hash$(i)
next i
end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|zkl}}==
885

edits