python 将一维列表转二维列表

增加并发性的需求, 将一维列表转为二维列表

if __name__ == "__main__":
    fd = open("domains.txt")
    domains = []
    domains = [domain.strip() for domain in fd.readlines() if domain.strip()]
    n = 1
    send_count = 1
    workcount = 5
    domains = split_list(domains, workcount)

def split_list(datas, n):
    """
    """
    length = len(datas)
    size = length /n + 1 if length % n  else length/n
    _datas = []
    for i in range(n):
        start = i * size
        end = (i + 1) * size
        _datas.append(datas[i * size: (i+1)*size])
    return _datas


你可能感兴趣的:(python学习)