Question: Write a function create _ social _ network ( traders ) that takes traders, a list of tuples specifing trader connections ( edges in the

Write a function create_social_network(traders) that takes traders, a list of tuples specifing trader connections (edges in the trader social network) and returns a list containing (trader, direct_connections) for each trader in traders.
Input:
traders: a list of tuples specifing trader connections (edges in the trader social network). Each tuple is of the form (trader1, trader 2) where trader 1 and trader 2 are string names of each trader.
Your function should return list of tuples in alphanumeric order of trader name, where each tuple is of the form (trader, direct_connections), and direct_connections is an alphanumerically sorted list of that trader's direct connections (i.e. there exists an edge between them in the trader social network).
You may assume:
Inputs are correctly formatted data structures and types. Just like Q1a, you don't need to guard against something like [('T1','T2'),('T2','T1')] or duplicate entries.
The pictured example:
) create_social_network(traders)
[('T1',['T2','T3']),('T2',['T1','T5']),('T3',['T1','T5','T6']),('T5',['T2','T3']),('T6',['T3'])]
Another example (not pictured):
create_social_network(traders)
 Write a function create_social_network(traders) that takes traders, a list of tuples

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!