Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago