2. Likes¶
Consider a scenario of a social network where people “gives likes” to each other. Let’s use an example represented in the follwing picture where nodes are people and directed arrows represent that the origin gave a like to the target:
The information about the “likes” can be represented in Python as a dictionary where the keys are person names in the network (str) and the associated value is the list of people names (list of str) to whom that person gave a like.
For example:
>>> likesD_1 = { ... 'kiku': ['laia', 'berta'], ... 'laia': ['pol', 'kiku'], ... 'nil': ['kiku', 'pol'], ... 'pol': ['berta', 'laia', 'kiku'], ... 'berta': ['kiku'], ... 'carla': ['laia', 'berta', 'kiku'], ... }
Note
We assume that all likes involve people appearing as a key in the dictionary (no likes to people who is not in the network.
You are required to implement the following functions and deliver them in the module likes (file likes.py).
The first function is:
- compute_likedby_dict(likesD)¶
such that
Note
The new dict must also include the people who did not receive any like, whose value will consequently be the empty list.
For example, the expected outpout for the above likes dict would be:
>>> correctD = { ... 'kiku': ['berta', 'carla', 'laia', 'nil', 'pol'], ... 'laia': ['carla', 'kiku', 'pol'], ... 'berta': ['carla', 'kiku', 'pol'], ... 'pol': ['laia', 'nil'], ... 'nil': [], ... 'carla': []}
Doctests are available in the compute_likedby_dict.test file.
The second function is:
- compute_matches_list(langD)¶
such that
For example, the expected outpout for the above example dict would be:
>>> correctL = [('berta', 'kiku'), ('kiku', 'laia'), ('laia', 'pol')]
Doctests are available in the compute_matches_list.test file.
