+ 6

[👑CHALLENGE👑]::Social Networks💑

Due to question being too long it has been moved down as the first post👇

30th Dec 2017, 3:43 AM
Poet🎭
Poet🎭 - avatar
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}
30th Dec 2017, 3:44 AM
Poet🎭
Poet🎭 - avatar
+ 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
30th Dec 2017, 9:52 AM
Sina Seirafi
Sina Seirafi - avatar
+ 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.
30th Dec 2017, 4:20 AM
Louis
Louis - avatar
+ 4
@There is no problem with the second input, it shows her whole group of friends including her herself
30th Dec 2017, 6:20 AM
Poet🎭
Poet🎭 - avatar
+ 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
31st Dec 2017, 5:19 AM
Louis
Louis - avatar
+ 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 😁
30th Dec 2017, 5:45 AM
Sina Seirafi
Sina Seirafi - avatar
+ 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.
30th Dec 2017, 5:51 AM
Sina Seirafi
Sina Seirafi - avatar
+ 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
30th Dec 2017, 6:22 AM
Poet🎭
Poet🎭 - avatar
+ 3
@Brains Sure👍
30th Dec 2017, 12:51 PM
Poet🎭
Poet🎭 - avatar
+ 3
@VcC Mine works.
2nd Jan 2018, 9:12 PM
Louis
Louis - avatar
+ 3
@VcC try mine, it works
3rd Jan 2018, 11:03 AM
Poet🎭
Poet🎭 - avatar
+ 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
30th Dec 2017, 6:24 AM
Poet🎭
Poet🎭 - avatar
+ 2
Hey Vito can I create a version of your code in web?Football match simulator?You'll get credits
30th Dec 2017, 8:06 AM
᠌᠌Code X
᠌᠌Code X - avatar
31st Dec 2017, 9:50 AM
VcC
VcC - avatar
+ 2
https://code.sololearn.com/cIstOnH71mVh/?ref=app Sorry for late submit, here's my solution
2nd Jan 2018, 7:52 PM
Poet🎭
Poet🎭 - avatar
+ 1
yeah
30th Dec 2017, 4:14 AM
Marius N'guessan
Marius N'guessan - avatar
0
Most of the codes dont work in the following case : [ ('Cindy','Mark'),('James','Henry'),('John','Nicky'),('Cindy','Esther'),("Mark","James")]...
2nd Jan 2018, 8:16 PM
VcC
VcC - avatar
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
2nd Jan 2018, 9:28 PM
VcC
VcC - avatar