Skip to content

Instantly share code, notes, and snippets.

@ajosanchez
Last active November 5, 2017 21:00
Show Gist options
  • Save ajosanchez/c69fe0d52e63801a0f4e1c9714752175 to your computer and use it in GitHub Desktop.
Save ajosanchez/c69fe0d52e63801a0f4e1c9714752175 to your computer and use it in GitHub Desktop.
this makes an adjacency list and decoding dictionary
import csv
import json
def make_adjacency_list(adj_list):
graph_list = []
people = {}
for person in adj_list:
for k,v in person[1].items():
person_id = person[0].keys()[0]
graph_list.append((person_id, k))
people.update({k:v})
people.update({person_id: person[0].values()[0]})
return graph_list, people
graph_list, people = make_adjacency_list(adjacency_list)
with open('wiki_graph.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(graph_list)
with open('people_dict.json', 'w') as f:
json.dump(people, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment