Internet: Structure, Statistical Analysis and Dynamic Evolution - Course Material

def barabasi(n, m):
   edges = []
   bag=[0]
   for i in xrange(1, n):
      for j in xrange(0,m):
         to = random.choice(bag)
         edges.extend(zip([i],[to]))
      bag.extend([i])
      bag.extend([e[h] for e in edges[-m:] for h in range(2)])
    return edges