2. Likes¶
Consider a scenario of a social network of people where anyone may “give a like” to anyone else. Graphically we have a number of nodes representing people and a number directed arrows representing a like given by the origin to the target. See the following example:
This information 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, hence there are no likes to people not belonging to 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.
