Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #338 Create a bidirectional map

Create a new bidirectional map bm and insert the pair (42, "forty-two")

import bidict
bm = bidict.bidict({42: 'forty-two'})
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
BiMap<Integer, String> bm = HashBiMap.create();
bm.put(42, "forty-two");

New implementation...
< >
programming-idioms.org