Simple comparison thingy. I have two lists and I want to compare if a value is larger than a value in the other list. The result is correct, however the structure is broken, I want the structure of the result list the same as the elements list.
comparelist = [0, 3000, 6000] elements = [[3], [4, 400], [3,4222]] result = [] for element in elements: for e in element: t = [] count = -1 for c in comparelist: if e > c: count +=1 else: t.append(comparelist[count]) break result.append(t) print(result) #Results in [[0], [0], [0], [0], [3000]] #I need [[0], [0, 0], [0, 3000]]Somewhat more pythonic way to write things ( I guess ... still learning )
comparelist = [0, 3000, 6000] elements = [[3], [4, 400], [3,4222]] result = [] for element in elements: for e in element: t = [] for index, value in enumerate(comparelist,-1): if e > value: pass else: t.append(comparelist[index]) break result.append(t) print(result)What am I doing wrong / what am I missing?