搜集共性项和所有项
###搜集共有参数值 def intersect(*args): res=[] for x in args[0]: for other in args[1:]: if x not in other :break else: res.append(x) return res ##搜集所有参数值 def union(*args): res=[] for seq in args: for x in seq: if not x in res: res.append(x) return res s1,s2,s3 = "SCAM","SBAM","SDAM" result=intersect(s1,s2,s3),union(s1,s2,s3) print(result)
结果 (['S', 'A', 'M'], ['S', 'C', 'A', 'M', 'B', 'D'])