Reference no: EM132368875
Question
You have been employed by Cambridge to analyse friendship groups on campus. Individuals have been allocated a number between 0 and the number of people on campus (minus one), and their friendships have been recorded as edges between numbered vertices. We assume friendships are always bi-directional. Cambridge has implemented this graph in a Python-readable format as an adjacency list. Create Python module called friends.py. Within this module implement the following task.
Write function popular(graph list, n) that returns a list of people who have at least n friends. Each person is identified by the number of their vertex.
Input: a nested list graph list that represents a graph as an adjacency list, that models the friendships at Cambridge; and a non-negative integer n.
Output: a list of integers, where each integer is a person with at least n friends. If no person has at least n friends, return an empty list.
The list may be in any order.
Examples: cambridge_list = [ [1,2,3], [0,3], [0,4], [0,1], [2] ]
NOTE: The example graph cambridge list is provided for illustrative purpose. Your implemented function must be able to handle arbitrary graphs in list form.
a) Calling popular(cambridge list,2) returns [0,1,2,3].
b) Calling popular(cambridge list,3) returns [0].
c) Calling popular(Cambridge list,0) returns [0,1,2,3,4].