Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for New Cities by Elena_Korljukova
def subnetworks(net, crushes):
b = [[i for i in x if all(i != j for j in crushes)] for x in net]
b = [i for i in b if i != []]
return len(b) - len([1 for i in b[:-1] if any(set(j)&set(i) != set() for j in b[b.index(i) + 1:])])
if __name__ == '__main__':
#print(subnetworks([["A","B"],["A","C"],["A","D"],["D","F"],["B","C"]],["A"]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert subnetworks([
['A', 'B'],
['B', 'C'],
['C', 'D']
], ['B']) == 2, "First"
assert subnetworks([
['A', 'B'],
['A', 'C'],
['A', 'D'],
['D', 'F']
], ['A']) == 3, "Second"
assert subnetworks([
['A', 'B'],
['B', 'C'],
['C', 'D']
], ['C', 'D']) == 1, "Third"
print('Done! Check button is waiting for you!')
Aug. 24, 2020