Вот вам ГОВНОКОДЕС, лень по уму делать, но и этот работает))
from collections import OrderedDict
src = [
u'DS4700_A2',
u'StorwizeAdd_p1',
u'DS4700_B2',
u'FAS_8200_initiator1_0f',
u'FirstClass_8200_1_0e',
u'FirstClass_8200_2_0e',
u'HP3parInf_1',
u'NetApp_8200_1_0e',
u'HP3parInf_2',
u'HUS_CL8A',
u'HUS_new_CL7A',
u'fas2650_2',
u'HUS_new_CL8A',
u'NetApp_8200_2_0e',
u'StorwizeAdd_p2',
u'Storwize_p1',
u'Storwize_p2',
u'FAS_8200_initiator2_0f',
u'fas2650_1',
u'HUS_CL7A',
u'H'
]
src = list(set(src))
src.sort(key=lambda x: len(x), reverse=True)
src1 = {}
for i, s in enumerate(src):
for j in range(0, len(s)):
sn = s if not j else s[:-j]
for s2 in src[i+1:]:
for l in range(0, len(s)):
sn1 = s2 if not l else s2[:-l]
if sn == sn1:
if sn not in src1:
src1[sn] = set()
src1[sn].add(s)
src1[sn].add(s2)
src2 = OrderedDict(sorted(src1.items(), key=lambda t: len(t[0]), reverse=True))
src2_keys = list(src2.keys())
for i, k in enumerate(src2_keys):
if k in src2.keys():
if not len(src2[k]):
src2.pop(k)
continue
if len(src2[k]) == 1:
key = src2[k].pop()
if k != key:
src2[key] = key
src2.pop(k)
continue
if i == len(src2_keys):
break
for value in src2[k]:
is_break = False
for j, k2 in enumerate(src2_keys[i+1:]):
if value in src2[k2]:
if len(src2[k]) == 1:
src2.pop(k)
is_break = True
break
else:
src2[k2].remove(value)
if is_break:
break
print(src2.keys())