def iid_divide(data, g):
    """divide list data among g groups each group has either int(len(data)/g)
    or int(len(data)/g)+1 elements returns a list of groups."""
    num_elems = len(data)
    group_size = int(len(data) / g)
    num_big_groups = num_elems - g * group_size
    num_small_groups = g - num_big_groups
    glist = []
    for i in range(num_small_groups):
        glist.append(data[group_size * i:group_size * (i + 1)])
    bi = group_size * num_small_groups
    group_size += 1
    for i in range(num_big_groups):
        glist.append(data[bi + group_size * i:bi + group_size * (i + 1)])
    return glist