Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Friends by altarfinch
from functools import reduce
class Friends:
connections = []
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 connection in self.connections:
self.connections.remove(connection)
return True
return False
def names(self):
return reduce(lambda a,b:a|b,self.connections)
def connected(self, name):
return reduce(lambda a,b:a|b,[c - {name} for c in self.connections if name in c]) if name in self.names() else set()
Feb. 11, 2015