Mar-31-2017, 02:06 PM
(This post was last modified: Mar-31-2017, 02:06 PM by richardbl27.)
Hi... I am relatively new to Python... I find it very interesting coming originally from a mainframe background.
I have a question. I'm trying to do a special sort on a list of tuples... Do I need to import anything
in order to use a lamda? I'm getting the following error message - any ideas why?
File "tuples.py", line 4
copied_list.sort(key=lamda x: (not x[0], x[1]))
^
Here is the code I have so far:
my_list = [(False, 'a'),(False, 'd'),(True, ''),(False,'h'),(True,'g')]
copied_list = my_list.copy()
copied_list.sort(key=lamda x: (not x[0], x[1]))
print copied_list
I have a question. I'm trying to do a special sort on a list of tuples... Do I need to import anything
in order to use a lamda? I'm getting the following error message - any ideas why?
File "tuples.py", line 4
copied_list.sort(key=lamda x: (not x[0], x[1]))
^
Here is the code I have so far:
my_list = [(False, 'a'),(False, 'd'),(True, ''),(False,'h'),(True,'g')]
copied_list = my_list.copy()
copied_list.sort(key=lamda x: (not x[0], x[1]))
print copied_list