data = [ ["#Siet", 10], ["Most-Hid", 11], ["Sme rodina", 11], ["SNS", 15], ["OLaNO-NOVA", 19], ["SaS", 21], ["Smer-SD", 49], ["LSNS", 14], ] # Nechcu spolu ndata = [ ["#Siet", "Smer-SD"], ["Most-Hid", "SNS"], ["SaS", "Smer-SD"], ["Smer-SD", "OLaNO-NOVA"], ["#Siet", "LSNS"], ["Most-Hid", "LSNS"], ["Sme rodina", "LSNS"], ["SNS", "LSNS"], ["OLaNO-NOVA", "LSNS"], ["SaS", "LSNS"], ["Smer-SD", "LSNS"], ] flags = [0,0,0,0,0,0,0,0] keys = [] output_data = [] for flags[0] in range(0, 2): for flags[1] in range(0, 2): for flags[2] in range(0, 2): for flags[3] in range(0, 2): for flags[4] in range(0, 2): for flags[5] in range(0, 2): for flags[6] in range(0, 2): for flags[7] in range(0, 2): strany = [] miesta = 0 for k in range(0,8): if flags[k] == 1: strany += [data[k][0]] miesta += data[k][1] ok = True for k in ndata: if k[0] in strany and k[1] in strany: ok = False if ok: key = "".join(strany) if not key in keys: keys += [key] output_data += [[miesta, strany]] for k in sorted(output_data, key=lambda i: i[0]): print k[0]*100.0/150.0, len(k[1]), k[1]