Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Friends solution in Clear category for Friends by Rolex
class Friends:
def __init__(self, connections):
self.connections = list(connections)
def add(self, connection):
if connection in self.connections:
return False
else:
self.connections.append(connection)
return True
def remove(self, connection):
if connection in self.connections:
self.connections.remove(connection)
return True
else:
return False
def names(self):
return set().union(*self.connections)
def connected(self, name):
return {n for n in self.names() if {n, name} in self.connections}
Dec. 24, 2017