>>> for subLi in x: ... if(xdictstart.has_key(subLi[0])): ... if(xdictstart[subLi[0]]>subLi[1]): ... xdictstart[subLi[0]]=subLi[1] ... else: ... xdictstart[subLi[0]]=subLi[1] The opposite can be done to obtain the xdictend.This is one way.There might be some easier way's but i'm not aware it.