How to convert an adjacency matrix to an adjacency list with python?
问题 I have an adjacency matrix like: [[ 0., 15., 0., 7., 10., 0.], [ 15., 0., 9., 11., 0., 9.], [ 0., 9., 0., 0., 12., 7.], [ 7., 11., 0., 0., 8., 14.], [ 10., 0., 12., 8., 0., 8.], [ 0., 9., 7., 14., 8., 0.]] How can I convert it to an adjacency list like this one down here? graph = {'1': [{'2':'15'}, {'4':'7'}, {'5':'10'}], '2': [{'3':'9'}, {'4':'11'}, {'6':'9'}], '3': [{'5':'12'}, {'6':'7'}], '4': [{'5':'8'}, {'6':'14'}], '5': [{'6':'8'}]} ? 回答1: Keep a list of already added edges in a set