+ 6
[👑CHALLENGE👑]::Social Networks💑
Due to question being too long it has been moved down as the first post👇
19 Answers
+ 7
*Challenge:Social Network*
In your class, many students are friends. Let’s assume that two students sharing a friend must be friends themselves; in other words, if students *Mark* and *Henry* are friends and students *Henry* and *Johnson* are friends, then students *Mark* and *Johnson* must be friends. Using this rule, we can partition the students into circles of friends.
To do this, implement a function networks() that takes two input arguments. The first is the number n of students in the class. We assume students are identified using their names. The second input argument is a list of tuple objects that define friends. For example, tuple ('Jessy','Bobby') defines students Jessy and Bobby as friends. Function networks() should print the partition of students into circles of friends as illustrated:
>>> networks(6, [('Cindy','Mark'),('Mark','Henry'),('John','Nicky'),('Cindy','Esther')])
Social network Mark is {'Mark','Cindy','Henry','Esther'}
Social network Cindy is {Cindy,Mark, Henry,Esther}
+ 5
I think network function, should take a name, and the list, in order to print "social network name is {}". Unless you want to print different circles, for each and every member, separately.
My code prints different circles once, makes use of that number of students to check if there are any alone students, and has a network function which takes a name, prints the requested name's social network.
https://code.sololearn.com/cb5fv7OYxNjy/?ref=app
+ 4
There needs to be a depth limmit on the assumption that friends are inherited. example.
If Henry is friends with Johnson and Johnson is friends with Mark. now Henry is friends with Mark.
works well for the first tier of relationship, but now Mark is friends with Esther thus Henry must be friends with Esther, and Esther with Roger, thus Henry must be friends with Roger and this goes on foreverer and everyone is friends with everyone.
+ 4
@There is no problem with the second input, it shows her whole group of friends including her herself
+ 4
I changed it so that you do not need to enter the number of friends, since it is superfluous.
https://code.sololearn.com/c8B093Ra1SpB/?ref=app
+ 3
I think in your example the second output should be {'John', 'Nicky'}, as Cidny is already in the first output, repeating it with a different order doesn't make a difference.
Edit : my bad 😁
+ 3
@Louis that depends on the input.
This method seperates students into different complete graphs, but doesn't necessarily go as far as everyone being friends with everyone. As in example, John doesn't have a friendship with anyone on the first group of friends. Therefore, there are at least two different groups.
+ 3
@Louis it depends on the type of example you should give an example of at most 6 - 8 friends
Seriously don't overcomplicate this, it's not at complex as you guys are making it out to be
+ 3
@Brains Sure👍
+ 3
@VcC
Mine works.
+ 3
@VcC try mine, it works
+ 2
But if you do want a depth limit you can make it so that the their secondary friends are only their friend's friends and not more than that
+ 2
Hey Vito can I create a version of your code in web?Football match simulator?You'll get credits
+ 2
+ 2
https://code.sololearn.com/cIstOnH71mVh/?ref=app
Sorry for late submit, here's my solution
+ 1
yeah
0
Most of the codes dont work in the following case : [
('Cindy','Mark'),('James','Henry'),('John','Nicky'),('Cindy','Esther'),("Mark","James")]...
0
@louis did you try with my example ? the point is that when you add a new vouple of friends, you need to merge two circles if each of them are in different circles