0

I want to create a weighted adjacency list (with weight=length) in Python from a graph that I downloaded.

Now, I struggle with creating such a list of the following form:

adjacency_list = { 'A': [('C', 8)],
'B': [(('A', 5), ('C', 1)], 'C': [('B', 12)]}

It is a directed Multigraph. Please help :)

PS; I tried using adj_list = nx.to_dict_of_dicts(G, edge_data='length'), but instead of the actual length it just writes "length" every time.

3
  • looks like homework Commented Aug 25, 2023 at 23:35
  • It is a part of a bigger project. This part I got stuck on. Commented Aug 26, 2023 at 9:55
  • I want to try out an algorithm, but in my case it needs this form. I work using networkx and osmnx. Commented Aug 26, 2023 at 9:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.