Apr-28-2020, 04:30 AM
hello everyone,
i am a python beginner and would like to understand a bit more about lambda, how to "read" it and when to use it instead of functions. I am working with a list of points (x,y,z) and using this block of code to sort the list based on the z value:
Question 2: why would I use lambda instead of a function anyway?
Cheers!
i am a python beginner and would like to understand a bit more about lambda, how to "read" it and when to use it instead of functions. I am working with a list of points (x,y,z) and using this block of code to sort the list based on the z value:
orglst.sort(key=lambda orglst:(orglst.Z,orglst.X,orglst.Y))now, this code works well. It was written by someone else and I cant really understand it because I am not familiar with lambda. I then tried to replace the lambda with a function, so I go a way I am familiar with, but it didnt work. In my mind, I was writing exactly the same instructions:
def reorder(list): return: list.Z,list.X,list.Y orglst.sort(key=reorder(orglst))then I tried something else, that also went wrong...
newlist = [] for point in orglst: newlist.append(point.Z) sort.orglst(key=newlist)Question 1: why are my alternatives not working?
Question 2: why would I use lambda instead of a function anyway?
Cheers!