Skip to content

Instantly share code, notes, and snippets.

@zoechi
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoechi/9f03791e75c4bcc8c7c2 to your computer and use it in GitHub Desktop.
Save zoechi/9f03791e75c4bcc8c7c2 to your computer and use it in GitHub Desktop.
SO 29565067 Inverse map
// 29565067
Map f = {
0 : 0,
1 : 1,
2 : 0,
3 : 1,
4 : 0,
5 : 1
};
main() {
print(f.keys.where((k) => f[k] == 0));
// or
print(new Map.fromIterable(f.values.toSet(),
key: (k) => k,
value: (v) => f.keys.where((k) => f[k] == v)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment