sA = sorted(fitResults['A'], key=lambda x: [i.fun if i is not None else np.inf for k, i in x.items()][0]) sE = sorted(fitResults['E'], key=lambda x: [i.fun if i is not None else np.inf for k, i in x.items()][0]) sAR = sorted(fitResultsReversed['A'], key=lambda x: [i.fun if i is not None else np.inf for k, i in x.items()][0]) sER = sorted(fitResultsReversed['E'], key=lambda x: [i.fun if i is not None else np.inf for k, i in x.items()][0])