Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Friends set solution in Clear category for Friends by flpo
from itertools import chain
class Friends:
def __init__(self, connections):
self.conn = set(map(frozenset, connections))
def add(self, connection):
if connection not in self.conn:
self.conn.add(frozenset(connection))
return True
return False
def remove(self, connection):
if connection in self.conn:
self.conn.remove(connection)
return True
return False
def names(self):
return set(chain.from_iterable(self.conn))
def connected(self, name):
return set(chain.from_iterable(x for x in self.conn if name in x)) - {name}
Jan. 2, 2018