Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
connections discard solution in Clear category for Friends by pskrdx
class Friends:
def __init__(self, connections):
self.connections = set(frozenset(i) for i in connections)
def add(self, connection):
if connection not in self.connections:
self.connections.add(frozenset(connection))
return True
else:
return False
def remove(self, connection):
if connection in self.connections:
self.connections.remove(connection)
return True
else:
return False
def names(self):
return set(sum([list(i)for i in self.connections],[]))
def connected(self, name):
s = set(sum([list(i)for i in self.connections if name in i],[]))
s.discard(name)
return s
Nov. 26, 2015