Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Friends by ssk8
from itertools import chain
class Friends:
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 not in self.connections:
return False
self.connections.remove(connection)
return True
def names(self):
return {*chain(*self.connections)}
def connected(self, n):
return {f for f in chain(*[c for c in self.connections if n in c]) if f != n}
Oct. 24, 2021