nanoBts = list() lists = [['sip', 'GSMExt.o2',200],['sip', 'GSMExt.Tm',200],['sip', 'GSMExt.Eplus',486],['sip', 'GSMExt.Voda',200],['GSMExt.o2','sip',200],['GSMExt.Voda','sip',200],['GSMExt.Eplus','sip',486],['GSMExt.Tm','sip',486]] def test(): for x in lists: call=x[0] dest=x[1] result=x[2] #print x if call[0:5]=='GSMEx': # looking for calling from GSMexternal found = False if len(nanoBts) == 0: nanoBts.append([call, result]) found = False else: delete = False for y in nanoBts: #find the existing result for GSM external in the list name = y[0] if name == call: if int(y[1]) == 486: delete = True nanoBts.remove(y) else: found = True if found != True: nanoBts.append([call, result]) if dest[0:5]=='GSMEx': # looking for destination call to GSMexternal found = False if len(nanoBts) == 0: nanoBts.append([dest,result]) found = False else: delete = False for y in nanoBts: name = y[0] if name == dest: if int(y[1]) == 486: delete = True item = y nanoBts.remove(y) else: found = True if found != True: nanoBts.append([dest,result]) #print nanoBts test() print nanoBts