Python task

11/28/2016 20:48 faakr#1
Hello!

If someone could help me or make me this script i would be really happy since i forgot that i need to make this until tomorow. I can offer league of legends, uplay, netflix accounts in return

Task:
pairs = {("Ana", "Berta"), ("Ana", "Greta"), ("Ana", "Helga"),
("Berta", "Cilka"), ("Berta", "Helga"),
("Cilka", "Dani"),
("Dani", "Ema"), ("Dani", "Greta"), ("Dani", "Helga"),
("Ema", "Fanci"), ("Ema", "Greta"), ("Ema", "Helga"),
("Fanci", "Iva"), ("Fanci", "Jana"), ("Fanci", "Klavdija"),
("Greta", "Helga")}

For simplicity and efficiency, every pair is listed just once, in alphabetic order (e.g. ("Ana", "Berta") and not also ("Berta", "Ana").

The other representation is a dictionary, where keys contain names and the corresponding values are sets of friends.

network = {"Ana": {"Berta", "Greta", "Helga"},
"Berta": {"Ana", "Helga", "Cilka"},
"Cilka": {"Berta", "Dani"},
"Dani": {"Cilka", "Ema", "Greta", "Helga"},
"Ema": {"Dani", "Fanci", "Greta", "Helga"},
"Fanci": {"Ema", "Iva", "Jana", "Klavdija"},
"Greta": {"Ana", "Dani", "Ema", "Helga"},
"Helga": {"Ana", "Berta", "Dani", "Ema", "Greta"},
"Iva": {"Fanci"},
"Jana": {"Fanci"},
"Klavdija": {"Fanci"}
}

The order here is unimportant (actually undefined, since we're dealing with dictionaries and sets). Note that here Berta is listed among Ana's friends and vice versa.
Here is a smaller network that also appears in tests.
Implement the following functions.

1.
• to_map(pairs) gets a list of pairs (like above) and returns a dictionary with the network (like below above).
• to_pairs(network) does the opposite.
• n_friends(network, n) gets a network (the second presentation) and returns a set of names of persons that have exactly n friends.
• lonely(network) returns a set of names of people with only a single friend.
• most_known(network) returns the name of the person with most friends.
• common_friends(network, name1, name2) returns a set of common friends of the two persons.

2.
• by_n_friends(network) returns a dictionary with keys from 1 to len(mreza) - 1 and the corresponding sets of people with that number of friends. For instance, for the small network, the function must return {1: {"D"}, 2: {"A", "B"}, 3: {"C"}}. See the example for the large network in the tests.
• suggestions(network) returns a list of pairs that are not friends but have at least one common friend. The pair must be sorted alphabetically (e.g. ("Ana", "Berta") and not ("Berta", "Ana")).
• clique(network, names) returns True if all persons from the group names know each other, and False otherwise.
• most_commons(network) returns the pair with the most mutual friends.

3.
• strangers(network, names) returns True if the group names contains absolute strangers - not even one pair knows each other -, and False otherwise.
• is_cover(network, names) returns True if the group "covers" the entire network in the sense that every person in the network is either in the group or is a friend with someone in the group.
• triangles(network) computes the number of "triangles" - triplets of people who know each other.

4.
• minimal_cover(mreza) returns the smallest set of names that cover the network (in the sense described at function is_cover, above).

5.
• Write all the above functions in a single line, except for to_dict, to_pairs, minimal_cover, most_known and most_commons. (The latter two are not complicated to write in a single line, but we haven't learned about that yet.)



Thanks
12/01/2016 23:08 0xFADED#2
Quote:
I can offer league of legends, uplay, netflix accounts in return
Maybe you should post this in [Only registered and activated users can see links. Click Here To Register...].