#!/usr/bin/env python
#encoding=utf-8
def unicode2str(input_str):
"""
将unicode类型转换为str类型
"""
if type(input_str)==type(u""):
return input_str.encode("utf-8","ignore")
return input_str
def str2unicode(str):
"""
将str类型转换为unicode类型
"""
if type(str)==type(u""):
return str
if type(str)==type(""):
return str.decode("utf-8","ignore")
a=["AC|||B","ABE|||ACFD","AB|||AC","ABD|||ACD"]
def do(a):
def cmp(x,y):
if x.__len__()<y.__len__():
return -1
elif x.__len__()==y.__len__():
return 0
else:
return 1
a.sort(cmp)
print a
abandom=set()
def _(a,b):
#a,b need unicode
#global abandom
aa=str2unicode(a)
bb=str2unicode(b)
r=bb.__len__()-aa.__len__()
print aa,bb
if r>0 and r%2==0:
laa,raa=aa.split("|||")
lbb,rbb=bb.split("|||")
if (laa in lbb) and (raa in rbb):
print "===>",aa,bb
idx=-1
for time in range(0,lbb.count(laa)):
idx=lbb.find(laa,idx+1)
print lbb[:idx]+lbb[idx+len(laa):]
if lbb[:idx]+lbb[idx+len(laa):]==rbb[:idx]+rbb[idx+len(raa):]:
abandom.add(b)
return a
if a.__len__<=1:
return abandom
for idx,elem in enumerate(a):
if idx==(len(a)-1):break
reduce(_,a[idx+1:],a[idx])
return abandom
print do(a)