May-29-2019, 07:01 PM
Now my clumsy brain has processed it and as a result I refactored your original code a little bit:
However, there is some ambiguity: what should be returned when condition fully or partially not met? (for example comparelist = [4500, 5000, 6000])
comparelist = [0, 3000, 6000] elements = [[3], [4, 400], [3,4222]] result = [] for element in elements: result.append([]) # add sublist for every list in elements for num in element: for value in reversed(comparelist): if value < num: result[-1].append(value) # append first match and break breakI assume that 'comparelist' is always sorted and starting from end is required to return closest match (in last case 3000 instead of 0)
However, there is some ambiguity: what should be returned when condition fully or partially not met? (for example comparelist = [4500, 5000, 6000])
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.