Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
second solution in Clear category for Friends by Tinus_Trotyl
class Friends:
def __init__(self, connections):
self.connections = list(connections)
def add(self, connection):
if connection in self.connections: return False
self.connections.append(connection)
return True
def remove(self, connection):
if not connection in self.connections: return False
self.connections.remove(connection)
return True
def names(self):
return set(name for pair in self.connections for name in pair)
def connected(self, name):
return set(tuple({name}^pair)[0] for pair in self.connections if name in pair)
Oct. 30, 2017