I have the next idea for this task. There's self._friends = dict of:
key - one friend
value - set of his friends
I have the next remove method
def remove(self, connection):
it = iter(connection)
friend1, friend2 = next(it), next(it)
ret = False
if friend1 in self._friends and friend2 in self._friends[friend1] or\
friend2 in self._friends and friend1 in self._friends[friend2]:
ret = True
if ret:
self._friends[friend1].remove(friend2)
self._friends[friend2].remove(friend1)
if not self._friends[friend1]:
del self._friends[friend1]
if not self._friends[friend2]:
del self._friends[friend2]
return ret
But test3/3 fails by return boolean value. Dunno what to do. Just tell me if that mistake by me? or not?
Created at: 2015/08/18 23:34; Updated at: 2015/08/18 23:36