import numpy as np
def split_receivers(receivers, senders):
count_for_sender = int(len(receiver) / len(sender))
chunk_count = int(len(receivers) / count_for_sender)
chunked_receivers = np.array_split(receivers, chunk_count)
return {s: r.tolist() for s, r in zip(senders, chunked_receivers)}
receiver = ['receiver1@mail.ru', 'receiver2@mail.ru', 'receiver3@mail.ru', 'receiver4@mail.ru', 'receiver5@mail.ru']
sender = ['sender1@mail.ru', 'sender@mail.ru']
split_receivers(receiver, sender)
# {'sender1@mail.ru': ['receiver1@mail.ru', 'receiver2@mail.ru', 'receiver3@mail.ru'], 'sender@mail.ru': ['receiver4@mail.ru', 'receiver5@mail.ru']}
Без зависимостей:
def split_list(l: list, n: int):
return [l[i::n] for i in range(n)]
receivers = [f'receiver{i}@mail.ru' for i in range(77)] # 77 получателей
senders = [f'sender{i}@mail.ru' for i in range(5)] # 5 отправителей
chunked_receivers = split_list(receivers, len(senders))
result = {s: r for s, r in zip(senders, chunked_receivers)}