Hash from two arrays

From Rosetta Code

Jump to: navigation, search
Task
Hash from two arrays
You are encouraged to solve this task according to the task description, using any language you may know.
Using two Arrays of equal length, create a Hash object where the elements from one array (the keys) are linked to the elements of the other (the values)

Contents

[edit] ActionScript

package
{
public class MyClass
{
public static function main():Void
{
var hash:Object = new Object();
var keys:Array = new Array("a", "b", "c");
var values:Array = new Array(1, 2, 3);
 
for (var i:int = 0; i < keys.length(); i++)
hash[keys[i]] = values[i];
}
}
}

[edit] Ada

Works with: GNAT version GPL 2007

with Ada.Strings.Hash;
with Ada.Containers.Hashed_Maps;
with Ada.Text_Io;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
 
procedure Hash_Map_Test is
function Equivalent_Key (Left, Right : Unbounded_String) return Boolean is
begin
return Left = Right;
end Equivalent_Key;
 
function Hash_Func(Key : Unbounded_String) return Ada.Containers.Hash_Type is
begin
return Ada.Strings.Hash(To_String(Key));
end Hash_Func;
 
package My_Hash is new Ada.Containers.Hashed_Maps(Key_Type => Unbounded_String,
Element_Type => Unbounded_String,
Hash => Hash_Func,
Equivalent_Keys => Equivalent_Key);
 
type String_Array is array(Positive range <>) of Unbounded_String;
 
Hash : My_Hash.Map;
Key_List : String_Array := (To_Unbounded_String("foo"),
To_Unbounded_String("bar"),
To_Unbounded_String("val"));
 
Element_List : String_Array := (To_Unbounded_String("little"),
To_Unbounded_String("miss"),
To_Unbounded_String("muffet"));
 
begin
for I in Key_List'range loop
Hash.Insert(Key => (Key_List(I)),
New_Item => (Element_List(I)));
end loop;
for I in Key_List'range loop
Ada.Text_Io.Put_Line(To_String(Key_List(I)) & " => " &
To_String(Hash.Element(Key_List(I))));
end loop;
 
end Hash_Map_Test;

[edit] Argile

Works with: Argile version 1.1.0

use std, array, hash
 
let keys = @["hexadecimal" "decimal" "octal" "binary"]
let values = @[0xa 11 014 0b1101] (: 10 11 12 13 :)
let hash = new hash of int
for each val int i from 0 to 3
hash[keys[i]] = values[i]
del hash hash

[edit] AWK

Awk arrays are used for both lists and hash maps.

$ awk 'BEGIN{split("one two three",a);
split("1 2 3",b);
for(i=1;i in a;i++){c[a[i]]=b[i]};
for(i in c)print i,c[i]
}'
three 3
two 2
one 1

[edit] C

There likely exist libraries that can be for creating hashes that are better than the following implementation. There are also better functions for obtaining hash values from strings. The following implementation tries to be somewhat generic to facilitate using alternative key and value types.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define KeyType const char *
#define ValType int
 
#define HASH_SIZE 4096
 
// hash function useful when KeyType is char * (string)
unsigned strhashkey( const char * key, int max)
{
unsigned h=0;
unsigned hl, hr;
 
while(*key) {
h += *key;
hl= 0x5C5 ^ (h&0xfff00000 )>>18;
hr =(h&0x000fffff );
h = hl ^ hr ^ *key++;
}
return h % max;
}
 
typedef struct sHme {
KeyType key;
ValType value;
struct sHme *link;
} *MapEntry;
 
typedef struct he {
MapEntry first, last;
} HashElement;
 
HashElement hash[HASH_SIZE];
 
typedef void (*KeyCopyF)(KeyType *kdest, KeyType ksrc);
typedef void (*ValCopyF)(ValType *vdest, ValType vsrc);
typedef unsigned (*KeyHashF)( KeyType key, int upperBound );
typedef int (*KeyCmprF)(KeyType key1, KeyType key2);
 
void HashAddH( KeyType key, ValType value,
KeyCopyF copyKey, ValCopyF copyVal, KeyHashF hashKey, KeyCmprF keySame )
{
unsigned hix = (*hashKey)(key, HASH_SIZE);
MapEntry m_ent;
 
for (m_ent= hash[hix].first;
m_ent && !(*keySame)(m_ent->key,key); m_ent=m_ent->link);
if (m_ent) {
(*copyVal)(&m_ent->value, value);
}
else {
MapEntry last;
MapEntry hme = malloc(sizeof(struct sHme));
(*copyKey)(&hme->key, key);
(*copyVal)(&hme->value, value);
hme->link = NULL;
last = hash[hix].last;
if (last) {
// printf("Dup. hash key\n");
last->link = hme;
}
else
hash[hix].first = hme;
hash[hix].last = hme;
}
}
 
int HashGetH(ValType *val, KeyType key, KeyHashF hashKey, KeyCmprF keySame )
{
unsigned hix = (*hashKey)(key, HASH_SIZE);
MapEntry m_ent;
for (m_ent= hash[hix].first;
m_ent && !(*keySame)(m_ent->key,key); m_ent=m_ent->link);
if (m_ent) {
*val = m_ent->value;
}
return (m_ent != NULL);
}
 
void copyStr(const char**dest, const char *src)
{
*dest = strdup(src);
}
void copyInt( int *dest, int src)
{
*dest = src;
}
int strCompare( const char *key1, const char *key2)
{
return strcmp(key1, key2) == 0;
}
 
void HashAdd( KeyType key, ValType value )
{
HashAddH( key, value, &copyStr, &copyInt, &strhashkey, &strCompare);
}
 
int HashGet(ValType *val, KeyType key)
{
return HashGetH( val, key, &strhashkey, &strCompare);
}
 
int main()
{
static const char * keyList[] = {"red","orange","yellow","green", "blue", "violet" };
static int valuList[] = {1,43,640, 747, 42, 42};
int ix;
 
for (ix=0; ix<6; ix++) {
HashAdd(keyList[ix], valuList[ix]);
}
return 0;
}

[edit] C++

By strict definition a std::map is not a hash, but it provides the same functionality. The C++-200x update to the C++ standard is incorporating hashes. When they are standardized the code below can change std::map to std::unordered_map and this will technically be a hash table. The core idea, turning two sequences into an associative mapping, is valid either way.

#include <map>
#include <string>
 
int
main( int argc, char* argv[] )
{
std::string keys[] = { "1", "2", "3" } ;
std::string vals[] = { "a", "b", "c" } ;
 
std::map< std::string, std::string > hash ;
 
for( int i = 0 ; i < 3 ; i++ )
{
hash[ keys[i] ] = vals[i] ;
}
}

Alternatively:

#include <map>       // for std::map
#include <algorithm> // for std::transform
#include <string> // for std::string
#include <utility> // for std::make_pair
 
int main()
{
std::string keys[] = { "one", "two", "three" };
std::string vals[] = { "foo", "bar", "baz" };
 
std::map<std::string, std::string> hash;
 
std::transform(keys, keys+3,
vals,
std::inserter(hash, hash.end()),
std::make_pair<std::string, std::string>);
}

[edit] C#

System.Collections.HashTable h = new System.Collections.HashTable();
 
string[] arg_keys = {"foo","bar","val"};
string[] arg_values = {"little", "miss", "muffet"};
 
//Some basic error checking
int arg_length = 0;
if ( arg_keys.Length == arg_values.Length ) {
arg_length = arg_keys.Length;
}
 
for( int i = 0; i < arg_length; i++ ){
h.add( arg_keys[i], arg_values[i] );
}

Alternate way of adding values

for( int i = 0; i < arg_length; i++ ){
h[ arg_keys[i] ] = arg_values[i];
}

[edit] Clojure

(zipmap [\a \b \c] [1 2 3])

[edit] Common Lisp

(defun rosetta-code-hash-from-two-arrays (vector-1 vector-2 &key (test 'eql))
(assert (= (length vector-1) (length vector-2)))
(let ((table (make-hash-table :test test :size (length vector-1))))
(map nil (lambda (k v) (setf (gethash k table) v))
vector-1 vector-2)
table))

Or, using cl:loop:

(defun rosetta-code-hash-from-two-arrays (vector-1 vector-2 &key (test 'eql))
(loop initially (assert (= (length vector-1) (length vector-2)))
with table = (make-hash-table :test test :size (length vector-1))
for k across vector-1
for v across vector-2
do (setf (gethash k table) v)
finally (return table)))

In Common Lisp terminology, a vector is a one-dimensional array.

[edit] D

import std.range: zip;
 
void main() {
auto keys = ["one", "two", "three"];
auto values = [1, 2, 3];
 
int[string] hash;
 
foreach (idx, key; keys)
hash[key] = values[idx];
 
// alternative using a zip
foreach (pair; zip(keys, values))
hash[pair.at!0] = pair.at!1;
}

[edit] E

def keys := ["one", "two", "three"]
def values := [1, 2, 3]
__makeMap.fromColumns(keys, values)

[edit] F#

HashMultiMap(Array.zip [|"foo"; "bar"; "baz"|] [|16384; 32768; 65536|], HashIdentity.Structural)

[edit] Factor

USING: hashtables ;
{ "one" "two" "three" } { 1 2 3 } zip >hashtable

[edit] Falcon

 
keys = [ 'a', 'b', 'c', 'd' ]
values = [ 1, 2, 3, 4 ]
hash = [ => ]
for i in [ 0 : keys.len() ]: hash[ keys[ i ] ] = values[ i ]
 

[edit] Groovy

keys = ['a','b','c']
vals = ['aaa', 'bbb', 'ccc']
hash = [:]
i = 0
keys.each { entry ->
hash.put(entry, vals[i++])
}

[edit] Haskell

Works with: GHCi version 6.6

import Data.Map
 
makeMap ks vs = fromList $ zip ks vs
mymap = makeMap ['a','b','c'] [1,2,3]

[edit] Icon and Unicon

[edit] Icon

link ximage    # to format the structure
 
procedure main(arglist) #: demonstrate hash from 2 lists
local keylist
 
if *arglist = 0 then arglist := [1,2,3,4] # ensure there's a list
every put(keylist := [], "key-" || !arglist) # make keys for each entry
 
every (T := table())[keylist[ i := 1 to *keylist ]] := arglist[i] # create the hash table
 
write(ximage(T)) # show result
end

[edit] Unicon

This Icon solution works in Unicon.

[edit] Ioke

{} addKeysAndValues([:a, :b, :c], [1, 2, 3])

[edit] J

Solution:

hash=: vals {~ keys&i.

For example:

   keys=: 10?.100 
vals=: > ;:'zero one two three four five six seven eight nine'
hash=: vals {~ keys&i.
 
keys
46 99 23 62 42 44 12 5 68 63
$vals
10 5
 
hash 46
zero
hash 99
one
hash 63 5 12 5 23
nine
seven
six
seven
two

Here, keys is a list of 10 integers between 0 and 99 chosen at random without repetition, and vals is a 10 by 5 character matrix.

[edit] Java

import java.util.HashMap;
public static void main(String[] args){
String[] keys= {"a", "b", "c"};
int[] vals= {1, 2, 3};
HashMap<String, Integer> hash= new HashMap<String, Integer>();
 
for(int i= 0; i < keys.length; i++){
hash.put(keys[i], vals[i]);
}
}

[edit] JavaScript

var keys = ['a', 'b', 'c'];
var values = [1, 2, 3];
var map = {};
for(var i in keys) {
map[ keys[i] ] = values[i];
}

[edit] Objective-C

NSArray *keys = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];
NSArray *values = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],
[NSNumber numberWithInt:2],
[NSNumber numberWithInt:3], nil];
NSDictionary *dict = [NSDictionary dictionaryWithObjects:values forKeys:keys];

[edit] OCaml

The idiomatic solution uses lists rather than arrays.

let keys = [ "foo"; "bar"; "baz" ]
and vals = [ 16384; 32768; 65536 ]
and hash = Hashtbl.create 0;;
 
List.iter2 (Hashtbl.add hash) keys vals;;

In the extremely unlikely event that it was actually necessary to use arrays, the solution would become slightly less elegant: (except using the ExtLib which provides the equivalent Array.iter2)

let keys = [| "foo"; "bar"; "baz" |]
and vals = [| 16384; 32768; 65536 |]
and hash = Hashtbl.create 0;;
 
for i = 0 to Array.length keys - 1 do
Hashtbl.add hash keys.(i) vals.(i)
done;;

In either case, an exception is raised if the inputs are different lengths.

If you want to use functional binary search trees instead of hash tables:

module StringMap = Map.Make (String);;
 
let keys = [ "foo"; "bar"; "baz" ]
and vals = [ 16384; 32768; 65536 ]
and map = StringMap.empty;;
 
let map = List.fold_right2 StringMap.add keys vals map;;

[edit] Oz

declare
fun {ZipRecord Keys Values}
{List.toRecord unit {List.zip Keys Values MakePair}}
end
 
fun {MakePair A B}
A#B
end
in
{Show {ZipRecord [a b c] [1 2 3]}}

[edit] Perl

my @keys = qw(a b c);
my @vals = (1, 2, 3);
my %hash;
@hash{@keys} = @vals;

Alternatively, using Library: List::MoreUtilsMoreUtils:

use List::MoreUtils qw(zip);
my %hash = zip @keys, @vals;

[edit] Perl 6

Works with: Rakudo version #23 "Lisbon"

my @keys = <a b c d e>;
my @vals = ^5;
my %hash = @keys Z @vals;

Alternatively:

my %hash;
%hash{@keys} = @vals;

To create an anonymous hash value, you can use Z as a "zipwith" metaoperator on the => pair composer:

{ <a b c d e> Z=> ^5 }

[edit] PHP

Works with: PHP version 5

$keys = array('a', 'b', 'c');
$values = array(1, 2, 3);
$hash = array_combine($keys, $values);

Works with: PHP version 4

$keys = array('a', 'b', 'c');
$values = array(1, 2, 3);
$hash = array();
for ($idx = 0; $idx < count($keys); $idx++) {
$hash[$keys[$idx]] = $values[$idx];
}

[edit] PicoLisp

(let (Keys '(one two three)  Values (1 2 3))
(mapc println
(mapcar cons Keys Values) ) )

Output:

(one . 1)
(two . 2)
(three . 3)

[edit] Pop11

vars keys = { 1 a b c};
vars vals = { 2 3 valb valc};
vars i;
;;; Create hash table
vars ht = newmapping([], 500, 0, true);
;;; Loop over input arrays (vectors)
for i from 1 to length(keys) do
vals(i) -> ht(keys(i));
endfor;

[edit] PowerShell

function create_hash ([array] $keys, [array] $values) {
$h = @{}
if ($keys.Length -ne $values.Length) {
Write-Error -Message "Array lengths do not match" `
-Category InvalidData `
-TargetObject $values
} else {
for ($i = 0; $i -lt $keys.Length; $i++) {
$h[$keys[$i]] = $values[$i]
}
}
return $h
}

[edit] Prolog

% this one with side effect hash table creation
 
:-dynamic hash/2.
 
make_hash([],[]).
make_hash([H|Q],[H1|Q1]):-
assert(hash(H,H1)),
make_hash(Q,Q1).
 
:-make_hash([un,deux,trois],[[a,b,c],[d,e,f],[g,h,i]])
 
 
% this one without side effects
 
make_hash_pure([],[],[]).
make_hash_pure([H|Q],[H1|Q1],[hash(H,H1)|R]):-
make_hash_pure(Q,Q1,R).
 
:-make_hash_pure([un,deux,trois],[[a,b,c],[d,e,f],[g,h,i]],L),findall(M,(member(M,L),assert(M)),L).

[edit] PureBasic

Dim keys.s(3)
Dim vals.s(3)
NewMap Hash.s()
 
keys(0)="a" : keys(1)="b" : keys(2)="c" : keys(3)="d"
vals(0)="1" : vals(1)="2" : vals(2)="3" : vals(3)="4"
For n = 0 To 3
Hash(keys(n))= vals(n)
Next
ForEach Hash()
Debug Hash()
Next

[edit] Python

Works with: Python version 2.3+

keys = ['a', 'b', 'c']
values = [1, 2, 3]
hash = dict(zip(keys, values))
 
# Lazily:
from itertools import izip
hash = dict(izip(keys, values))

Works with: Python version 3.0+ Shows off the dict comprehensions in Python 3:

keys = ['a', 'b', 'c']
values = [1, 2, 3]
hash = {key: value for key, value in zip(keys, values)}

Works with: Python(any version)

keys = ['a', 'b', 'c']
values = [1, 2, 3]
hash = {}
for i range(len(keys)):
hash[keys[i]] = values[i]

The original (Ruby) example uses a range of different types as keys. Here is similar in python (run at the shell):

>>> class Hashable(object):
def __hash__(self):
return id(self) ^ 0xBEEF
 
 
>>> my_inst = Hashable()
>>> my_int = 1
>>> my_complex = 0 + 1j
>>> my_float = 1.2
>>> my_string = "Spam"
>>> my_bool = True
>>> my_unicode = u'Ham'
>>> my_list = ['a', 7]
>>> my_tuple = ( 0.0, 1.4 )
>>> my_set = set(my_list)
>>> def my_func():
pass
 
>>> class my_class(object):
pass
 
>>> keys = [my_inst, my_tuple, my_int, my_complex, my_float, my_string,
my_bool, my_unicode, frozenset(my_set), tuple(my_list),
my_func, my_class]
>>> values = range(12)
>>> d = dict(zip(keys, values))
>>> for key, value in d.items(): print key, ":", value
 
1 : 6
1j : 3
Ham : 7
Spam : 5
(0.0, 1.3999999999999999) : 1
frozenset(['a', 7]) : 8
1.2 : 4
('a', 7) : 9
<function my_func at 0x0128E7B0> : 10
<class '__main__.my_class'> : 11
<__main__.Hashable object at 0x012AFC50> : 0
>>>

[edit] R

Assuming that the keys are coercible to character form, we can simply use the names attribute to create a hash. This example is taken from the Wikipedia page on hash tables.

# Set up hash table
keys <- c("John Smith", "Lisa Smith", "Sam Doe", "Sandra Dee", "Ted Baker")
values <- c(152, 1, 254, 152, 153)
names(values) <- keys
# Get value corresponding to a key
values["Sam Doe"] # vals["Sam Doe"]
# Get all keys corresponding to a value
names(values)[values==152] # "John Smith" "Sandra Dee"

[edit] Raven

[ 'a' 'b' 'c' ] as $keys [ 1 2 3 ] as $vals
$keys $vals combine as $hash

[edit] Ruby

keys=['hal',666,[1,2,3]]
vals=['ibm','devil',123]
hash = Hash[keys.zip(vals)] # Ruby 1.8.7 and later
hash = Hash[*keys.zip(vals).flatten] # pre-1.8.7
# now hash => {'hal' => 'ibm', 666 => 'devil', [1,2,3] => 123}
 
#retrieve the value linked to the key [1,2,3]
puts hash[ [1,2,3] ]
#123

[edit] Sather

class ZIPPER{K,E} is
zip(k:ARRAY{K}, e:ARRAY{E}) :MAP{K, E}
pre k.size = e.size
is
m :MAP{K, E} := #;
loop m[k.elt!] := e.elt!; end;
return m;
end;
end;
 
class MAIN is
 
main is
keys:ARRAY{STR} := |"one", "three", "four"|;
values:ARRAY{INT} := |1, 3, 4|;
m ::= ZIPPER{STR,INT}::zip(keys, values);
loop
#OUT + m.pair! + " ";
end;
#OUT + "\n";
end;
 
end;

[edit] Scala

val keys = Array(1, 2, 3)
val values = Array("A", "B", "C")
val map = Map(keys.zip(values) : _*)
// returns Map(1 -> "A", 2 -> "B", 3 -> "C")
// keys.zip(values) is an array of pairs : Array((1, "A"), (2, "B"), (3, "C"))
// Map(...) expects multiple pairs arguments. Syntax ": _*" tells the single argument contains multiple values.

[edit] Scheme

Using SRFI 69:

(define (lists->hash-table keys values . rest)
(apply alist->hash-table (map cons keys values) rest))

[edit] Seed7

$ include "seed7_05.s7i";
 
const type: numericHash is hash [string] integer;
var numericHash: myHash is numericHash.value;
 
const proc: main is func
local
var array string: keyList is [] ("one", "two", "three");
var array integer: valueList is [] (1, 2, 3);
var integer: number is 0;
begin
for number range 1 to length(keyList) do
myHash @:= [keyList[number]] valueList[number];
end for;
end func;

[edit] Smalltalk

Works with: GNU Smalltalk

Array extend [
dictionaryWithValues: array [ |d|
d := Dictionary new.
1 to: ((self size) min: (array size)) do: [:i|
d at: (self at: i) put: (array at: i).
].
^ d
]
].
 
 
({ 'red' . 'one' . 'two' }
dictionaryWithValues: { '#ff0000'. 1. 2 }) displayNl.

[edit] SNOBOL4

Works with: Macro Spitbol Works with: Snobol4+ Works with: CSnobol

*       # Fill arrays
keys = array(5); vals = array(5)
ks = 'ABCDE'; vs = '12345'
kloop i = i + 1; ks len(1) . keys<i> = :s(kloop)
vloop j = j + 1; vs len(1) . vals<j> = :s(vloop)
 
* # Create hash
hash = table(5)
hloop k = k + 1; hash<keys<k>> = vals<k> :s(hloop)
 
* # Test and display
ts = 'ABCDE'
tloop ts len(1) . ch = :f(out)
str = str ch ':' hash<ch> ' ' :(tloop)
out output = str
end

Output:

A:1 B:2 C:3 D:4 E:5

[edit] Standard ML

Works with: SML/NJ Using functional binary search trees instead of hash tables:

structure StringMap = BinaryMapFn (struct
type ord_key = string
val compare = String.compare
end);
 
val keys = [ "foo", "bar", "baz" ]
and vals = [ 16384, 32768, 65536 ]
and myMap = StringMap.empty;
 
val myMap = foldl StringMap.insert' myMap (ListPair.zipEq (keys, vals));

Works with: SML/NJ Using hash tables:

exception NotFound;
 
val keys = [ "foo", "bar", "baz" ]
and vals = [ 16384, 32768, 65536 ]
and hash = HashTable.mkTable (HashString.hashString, op=) (42, NotFound);
 
ListPair.appEq (HashTable.insert hash) (keys, vals);

[edit] Tcl

Arrays in Tcl are automatically associative, i.e. there are no "not hashed arrays". If we can take "arrays of equal length" to mean "lists of equal length", then the task might look like this:

set keys [list fred bob joe]
set values [list barber plumber tailor]
array set arr {}
foreach a $keys b $values { set arr($a) $b }

Alternatively, a dictionary could be used:

foreach a $keys b $values {
dict set jobs $a $b
}

[edit] UnixPipes

Using a sorted file as an associative array (see Creating an associative array for usage.)

cat <<VAL >p.values
apple
boy
cow
dog
elephant
VAL
 
cat <<KEYS >p.keys
a
b
c
d
e
KEYS
 
paste -d\ <(cat p.values | sort) <(cat p.keys | sort)

[edit] Ursala

There's a built in operator for this.

keys   = <'foo','bar','baz'>
values = <12354,145430,76748>
 
hash_function = keys-$values

test program:

#cast %nL
 
test = hash_function* <'bar','baz','foo','bar'>

output:

<145430,76748,12354,145430>

[edit] VBScript

VBScript (and Visual Basic in general) calls hashes "dictionary objects".

Set dict = CreateObject("Scripting.Dictionary")
os = Array("Windows", "Linux", "MacOS")
owner = Array("Microsoft", "Linus Torvalds", "Apple")
For n = 0 To 2
dict.Add os(n), owner(n)
Next
MsgBox dict.Item("Linux")
MsgBox dict.Item("MacOS")
MsgBox dict.Item("Windows")

Output:

Linus Torvalds
Apple
Microsoft

[edit] Visual Basic

Translation of: VBScript

Library: Microsoft Scripting Runtime (scrrun.dll)

The VBScript version can be used in Visual Basic unchanged, but this version explicitly declares dict as a dictionary, rather than setting a Variant to a Dictionary object.

Normally, I prefer to explicitly declare all variables, and I strongly dislike variants, but in this instance variants are apparently required, because Array() doesn't like anything else. (In a real program, I probably wouldn't load the arrays with Array(), therefore allowing me to declare those arrays as strings, but it was a simple expendiant for this example.)

Dim dict As New Dictionary
os = Array("Windows", "Linux", "MacOS")
owner = Array("Microsoft", "Linus Torvalds", "Apple")
For n = 0 To 2
dict.Add os(n), owner(n)
Next
Debug.Print dict.Item("Linux")
Debug.Print dict.Item("MacOS")
Debug.Print dict.Item("Windows")

[edit] Visual Basic .NET

Dim names = New String() {"Frank", "Tom", "Jones"}
Dim grades = New Integer() {90, 87, 96}
 
 
Dim hash = New Dictionary(Of String, Integer)
For i = 0 To names.Length - 1
hash.Add(names(i), grades(i))
Next
Personal tools
Support