I have a list of tuples. Each tuple represents a person in a social network. The first item is their id or "name". The second is a dictionary; each key is another person in the network with whom they have mutual connections, and its value is how many mutuals they have together.
network = [
(6, {3: 3, 4: 3, 7: 2, 1: 3, 11: 2}),
(1, {7: 3, 11: 4, 6: 3, 4: 3}),
(4, {3: 2, 6: 3, 1: 3, 11: 2, 12: 3}),
(2, {9: 4, 8: 2, 10: 2, 5: 2}),
(12, {3: 2, 4: 3}),
(3, {5: 2, 8: 2, 12: 2, 4: 2, 7: 2, 6: 3}),
(10, {2: 2, 9: 3, 8: 3, 5: 2}),
(5, {3: 2, 8: 3, 9: 4, 10: 2, 2: 2}),
(13, {}),
(8, {2: 2, 9: 3, 10: 3, 3: 2, 5: 3}),
(7, {3: 2, 6: 2, 1: 3}),
(11, {1: 4, 6: 2, 4: 2}),
(9, {2: 4, 8: 3, 10: 3, 5: 4}),
]
If two people have 1, 2, or 3 mutuals, they might know each other. If they have 4 mutuals, they probably know each other. I want to process this list so that I can determine who might/probably knows whom, resulting in output like this:
Name: 1
Might know: 4, 6, 7
Probably knows: 11
Name: 2
Might know: 5, 8, 10
Probably knows: 9
Name: 3
Might know: 4, 5, 6, 7, 8, 12
Probably knows:
Name: 4
Might know: 1, 3, 6, 11, 12
Probably knows:
Name: 5
Might know: 2, 3, 8, 10
Probably knows: 9
Name: 6
Might know: 1, 3, 4, 7, 11
Probably knows:
Name: 7
Might know: 1, 3, 6
Probably knows:
Name: 8
Might know: 2, 3, 5, 9, 10
Probably knows:
Name: 9
Might know: 8, 10
Probably knows: 2, 5
Name: 10
Might know: 2, 5, 8, 9
Probably knows:
Name: 11
Might know: 4, 6
Probably knows: 1
Name: 12
Might know: 3, 4
Probably knows:
Here is my code I'm currently using to process it:
might = []
probably = []
for person in network:
name = person[0]
connections = person[1]
for other_name, mutuals in connections.items():
if mutuals > 3:
probably.append(str(other_name))
else:
might.append(str(other_name))
But I only end up with my two lists:
['3', '4', '7', '1', '11', '7', '6', '4', '3', '6', '1', '11', '12', '8', '10',
'5', '3', '4', '5', '8', '12', '4', '7', '6', '2', '9', '8', '5', '3', '8',
'10', '2', '2', '9', '10', '3', '5', '3', '6', '1', '6', '4', '8', '10']
['11', '9', '9', '1', '2', '5']
How can I associate these with the proper names?