#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 10 17:08:21 2020

@author: nedeleg
"""

import logging

from casadi import *


def checkListEqual(lst):
    return not lst or [lst[0]] * len(lst) == lst


def listOfDict(kwargs):
    Nlist = [len(kwargs[key]) for key in kwargs if type(kwargs[key]) == type([])]
    if Nlist != []:
        if not checkListEqual(Nlist):
            raise Exception("The inputs length are not compatible")
        N = Nlist[0]
        inputs = []
        for i in range(N):
            tmp = {}
            for key in kwargs:
                if type(kwargs[key]) == type([]):
                    tmp[key] = kwargs[key][i]
                else:
                    tmp[key] = kwargs[key]
            inputs.append(tmp)
    else:
        inputs = [kwargs]
    return inputs


def dictOfList(list_of_dict):
    res = {
        key: [list_of_dict[i][key] for i in range(len(list_of_dict))]
        for key in list_of_dict[0]
    }
    return res
