Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Friends by sebastian.okseniuk
class Friends:
def __init__(self, connections):
self.connections = set([frozenset(i) for i in connections])
def add(self, connection):
connection = frozenset(connection)
if connection in self.connections:
return False
else:
self.connections.add(connection)
return True
def remove(self, connection):
connection = frozenset(connection)
if connection in self.connections:
self.connections.remove(connection)
return True
else:
self.connections.add(connection)
return False
def names(self):
return {name for sublist in self.connections for name in sublist }
def connected(self, name):
return {item for sublist in self.connections
if name in sublist for item in sublist if item != name }
Dec. 2, 2015