Ask a question to Desklib · AI bot


Social Network Analysis: Functions for Friendships and Groups in Python

Added on -2019-09-18

This text describes two representations of a social network: one as a set of pairs of friends, and the other as a dictionary where keys are names and values are sets of friends. It also lists several functions that can be implemented to analyze the network, such as finding the number of friends each person has, suggesting new friendships, checking if a group of people are all friends, finding the pair with the most mutual friends, checking if a group contains strangers, checking if a group covers the entire network, counting the number of triangles (triplets of people who know each other), and finding the smallest set of names that cover the network.

| 2 pages
| 711 words

Trusted by 2+ million users,
1000+ happy students everyday

pairs = {("Ana", "Berta"), ("Ana", "Greta"), ("Ana", "Helga"), ("Berta", "Cilka"), ("Berta", "Helga"), ("Cilka", "Dani"), ("Dani", "Ema"), ("Dani", "Greta"), ("Dani", "Helga"), ("Ema", "Fanči"), ("Ema", "Greta"), ("Ema", "Helga"), ("Fanči", "Iva"), ("Fanči", "Jana"), ("Fanči", "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 = {"Ana": {"Berta", "Greta", "Helga"}, "Berta": {"Ana", "Helga", "Cilka"}, "Cilka": {"Berta", "Dani"}, "Dani": {"Cilka", "Ema", "Greta", "Helga"}, "Ema": {"Dani", "Fanči", "Greta", "Helga"}, "Fanči": {"Ema", "Iva", "Jana", "Klavdija"}, "Greta": {"Ana", "Dani", "Ema", "Helga"}, "Helga": {"Ana", "Berta", "Dani", "Ema", "Greta"}, "Iva": {"Fanči"}, "Jana": {"Fanči"}, "Klavdija": {"Fanči"} }

Found this document preview useful?

You are reading a preview
Upload your documents to download
Become a Desklib member to get accesss

Students who viewed this