def make_segments(mailchimp, list_id, count, emails):
 if (count > 0):
  segments = mailchimp.listStaticSegments(id=list_id)
  for seg in segments:
   if seg['name'].startswith('random'):
    mailchimp.listStaticSegmentDel(id=list_id, seg_id=seg['id'])
  emails = list(emails)
  random.shuffle(emails)
  chunk_size = int(math.ceil((float(len(emails)) / count)))
  chunks = list(chunk(emails, chunk_size))
  for seg in xrange(count):
   name = 'random_{0:002}'.format(seg)
   seg_id = mailchimp.listStaticSegmentAdd(id=list_id, name=name)
   for batch in chunk(chunks[seg], BATCH_SIZE):
    mailchimp.listStaticSegmentMembersAdd(id=list_id, seg_id=seg_id, batch=batch)

def make_segments ( mailchimp , list_id , count , emails ) : if ( count > 0 ) : segments = mailchimp . listStaticSegments ( id = list_id ) for seg in segments : if seg [ 'name' ] . startswith ( 'random' ) : mailchimp . listStaticSegmentDel ( id = list_id , seg_id = seg [ 'id' ] ) emails = list ( emails ) random . shuffle ( emails ) chunk_size = int ( math . ceil ( ( float ( len ( emails ) ) / count ) ) ) chunks = list ( chunk ( emails , chunk_size ) ) for seg in xrange ( count ) : name = 'random_{0:002}' . format ( seg ) seg_id = mailchimp . listStaticSegmentAdd ( id = list_id , name = name ) for batch in chunk ( chunks [ seg ] , BATCH_SIZE ) : mailchimp . listStaticSegmentMembersAdd ( id = list_id , seg_id = seg_id , batch = batch )
segments the list of email addresses emails into count segments .