One possible answer is that you should keep a set of the ones you've added so far... self.macaddrtable = {} self.macaddrs = set()
... if (packet.src,packet.dst) not in self.macaddrs: self.macaddrs.add((packet.src,packet.dst])) self.macaddrtable[f_id]=(packet.src,packet.dst) f_id=f_id+1 There might be better things to be done, but it's impossible to say without knowing more (e.g., what you're trying to accomplish, what f_id is used for, etc.). -- Murphy On Nov 9, 2013, at 10:35 AM, Sayed Qaiser Ali Shah <11msitqs...@seecs.edu.pk> wrote: > Hello everybody, > > I have defined dictionary in POX controller and I by the name addrtable and I > am saving two things in this dictionary i.e. Source mac and destination mac. > What I have done is > > self.macaddrtable = {} > ... > f_id=1 > self.macaddrtable[f_id]={packet.src, packet.dst} > print self.macaddrtable > f_id=f_id+1 > > It is saving source mac and destination mac in the dictionary but the problem > is when f_id increases it then save same source and destination mac again and > again. > What I want is to save mac address only if its not in dictionary.