from collections import defaultdict def epidemic(self, packet, state): ''' Routes a packet if it hasn't sent the packet on a link yet. Always returns False. ''' if 'sent' not in state: state['sent'] = defaultdict(dict) sent = state['sent'] for met in self.links: if packet not in sent[met]: sent[met][packet] = True self.send(met, packet) return False