Last active
January 30, 2021 12:52
-
-
Save gidgid/6a36d3fd10d7cac0a91a94f4fbe6df63 to your computer and use it in GitHub Desktop.
shows how we can manually run flatten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Set | |
def flatten_multivalues(key_to_values: Dict[str, Set[int]]) -> Set[int]: | |
all_values = set() | |
for values in key_to_values.values(): | |
all_values.update(values) | |
return all_values | |
def test_flattens_multivalue_dicts(): | |
# shamelessly taken from: https://www.elastic.co/blog/found-elasticsearch-from-the-bottom-up | |
term_to_document_indices = { | |
"choice": {3}, | |
"coming": {1}, | |
"fury": {2}, | |
"is": {1, 2, 3}, | |
"the": {2, 3}, | |
} | |
all_document_indices = flatten_multivalues(term_to_document_indices) | |
assert all_document_indices == {1, 2, 3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment