79309955

Date: 2024-12-26 16:41:35
Score: 1.5
Natty:
Report link

Not sure what you are going for, but assuming "similarity" means a bidirectional edge between the two characters, you can create an adjacency graph and perform a depth first search in order to cluster similarity.

Next time please show what you have tried before posting a question. The SO community is not here to write code for you... but nevertheless, I wrote some untested code to give you an idea.

col_combi = [('a','b'), ('b','c'), ('d','e'), ('l','j'), ('c','g'), ('e','m'), ('m','z'), ('z','p'), ('t','k'), ('k', 'n'), ('j','k')]

adj = {}

for item in col_combi:
    if item[0] not in adj.keys():
        adj[item[0]] = []
    if item[1] not in adj.keys():
        adj[item[1]] = []
    adj[item[0]].append(item[1])
    adj[item[1]].append(item[0])
visited = set()

curr = []
def dfs(node):
    curr.append(node)
    visited.add(node)
    if adj.get(node) != None:
        for neighbor in adj.get(node):
            if neighbor not in visited:
                dfs(neighbor)
clutter = []
for value in adj.keys():
    if (value not in visited):
        dfs(value)
        delim = ""
        for node in curr:
            print(delim + node, end = "")
            delim = "-"
        print(" ")
        curr = []
Reasons:
  • RegEx Blacklisted phrase (2.5): please show what you
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: TheHappyBee