Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Friends by merlengross
class Friends:
def __init__(self, connections):
self.connections = list(connections)
def add(self, connection):
if connection not in self.connections:
self.connections.append(connection)
return True
return False
def remove(self, connection):
if connection in self.connections:
self.connections.remove(connection)
return True
return False
def names(self):
names = set()
for connection in self.connections:
names = names | connection
return names
def connected(self, name):
names = set()
for connection in self.connections:
if name in connection:
names.update(connection ^ {name})
return names
Jan. 6, 2015
Comments: