Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Having fun with Tinus_Trotyl's solution :) solution in Creative category for Friends by suic
# Source: https://py.checkio.org/mission/friends/publications/Tinus_Trotyl/python-3/at-last-my-final-solution-with-a-little-bit-of-help-from-tom-tom-and-sukonnik-illia/share/bf19c983ce49bfe01df0e5a80e39ffc1/
from itertools import chain
class Friends:
def __init__(self, connections):
self.connections = set(map(frozenset, connections))
def add(self, connection):
return connection not in self.connections and not self.connections.add(frozenset(connection))
def remove(self, connection):
return connection in self.connections and not self.connections.remove(connection)
def names(self):
return set(chain.from_iterable(self.connections))
def connected(self, name):
return {({name}^pair).pop() for pair in self.connections if name in pair}
Feb. 27, 2018
Comments: