Nov-14-2017, 02:38 AM
network= [['0 1'], ['0 2'], ['0 3'], ['1 4'], ['1 6'], ['1 7'], ['1 9'], ['2 3'], ['2 6'], ['2 8'], ['2 9']]
I have a list of lists (above) and I am trying to create a list of tuples where it looks like this:
[(0, [1, 2, 3]), (1, [0, 4, 6, 7, 9]), (2, [0, 3, 6, 8, 9]),]
So far I have:
And it outputs:
[('0', 1), ('0', 2), ('0', 3), ('1', 4), ('1', 5), ('1', 6), ('1', 7), ('2', 8), ('2', 9), ('2', 10), ('2', 11)]
I am unsure how to take the next step,plus this output is wrong, how do I convert this into what is expected
Please help
I have a list of lists (above) and I am trying to create a list of tuples where it looks like this:
[(0, [1, 2, 3]), (1, [0, 4, 6, 7, 9]), (2, [0, 3, 6, 8, 9]),]
So far I have:
network= [['0 1'], ['0 2'], ['0 3'], ['1 4'], ['1 6'], ['1 7'], ['1 9'], ['2 3'], ['2 6'], ['2 8'], ['2 9']] friends=[] for i in range(len(network)): element= (network[i][0][0], i+1) friends.append(element) print(friends)
And it outputs:
[('0', 1), ('0', 2), ('0', 3), ('1', 4), ('1', 5), ('1', 6), ('1', 7), ('2', 8), ('2', 9), ('2', 10), ('2', 11)]
I am unsure how to take the next step,plus this output is wrong, how do I convert this into what is expected
Please help