Skip to content

Instantly share code, notes, and snippets.

@junetech
Created September 25, 2024 16:02
Show Gist options
  • Save junetech/40653af981d732e5e74b81cae6d2f88f to your computer and use it in GitHub Desktop.
Save junetech/40653af981d732e5e74b81cae6d2f88f to your computer and use it in GitHub Desktop.
Utilities with hypergraph dictionary input
from typing import Any
from collections.abc import Hashable, Iterable
from itertools import combinations
def calc_adjacency_dict(hypergraph_dict: dict[Hashable, Iterable[Hashable]]) -> dict[Hashable, set[Hashable]]:
key_list = list(hypergraph_dict.keys())
hypergraph_set_dict = {key: set(hypergraph_dict[key]) for key in key_list}
return_dict = {key: set() for key in key_list}
for key1, key2 in combinations(key_list, 2):
if hypergraph_set_dict[key1] & hypergraph_set_dict[key2]:
return_dict[key1].add(key2)
return_dict[key2].add(key1)
return return_dict
print("Hello world!")
my_hypergraph = {11: [1, 2, 3], 22: [3], 33: [2]}
print(calc_adjacency_dict(my_hypergraph))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment