#coding:utf-8 mylist = ['X','Y','Z'] halfkuohao = '(' halfkuohao2 =')' luojilist = ['&','|'] for i in mylist: biaodashi = '' biaodashi += i for l1 in luojilist: l1 = i+l1 for j in mylist: if(j != i): l3 = l1 +'(' l3 += j l5 =l3 for l2 in luojilist: l3 = l5 +l2 for k in mylist: if((k != i) and (k != j)): l3 += k l3 = l3 +')' print l3