
def split_seq(seq, size):
    return [seq[i:i+size] for i in range(0, len(seq), size)]

def mergeNestedSequence(seq):
    merged = []
    for s in seq:
        merged.extend(s)
    return merged

def split_by_count(seq, maxSize):
    size = len(seq)
    if size > maxSize:
        m = size % maxSize
        splitsize = (size/maxSize)
        if m > 0:
            splitsize = splitsize+1
        return split_seq(seq, splitsize)
    return [seq]

""" This will split dictionary into specified numbers of dictionaries """
def split_dict(dictJSON, size, keyName='LiveJSON_'):
    splitedDict = dict()
    splitsize = round(1.0/size*len(dictJSON))
    dictNo=1
    d = dict()
    count=0
    for key in dictJSON:
        if count==splitsize:
            splitedDict[keyName+`dictNo`] = d
            dictNo += 1
            # Reset dictionary & count
            d = dict()
            count=0

        d[key]=dictJSON[key]
        count+=1

    # Append Last set of dictionaries List
    splitedDict[keyName+`dictNo`] = d
    return splitedDict

def _split_dict_(dictJSON, size):
    return [dict(tup) for tup in split_seq(dictJSON.items(), size)]
