i generate a population type class Person. They have 50 elements(self.people) and for this elements i try to create a friendship from this population. In code "for j in self...." i create a new list and remove elements with index j, because person can't be friend itself. When code is running i see that in my list self.people had 25 elements. What is wrong in my code. Thx
def generate_population(self, n, friends_count):
for i in range(n):
self.people.append(person.Person(threshold=random.random(), interested_in=random.sample(news.CATEGORIES, 1)))
for j in self.people:
fr_list = self.people
fr_list.remove(j)
j.make_friends(fr_list, friends_count)
def make_friends(self, population, n):
fr_list = population
random_friends = random.sample(fr_list, n)
for i in random_friends:
self.friends_list.append(i)