Skip to content

Commit 6ccbc07

Browse files
committed
Demonstration of lambda functions using the sort function
1 parent 7d6edab commit 6ccbc07

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

week-02/placeholder.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
Slides are at https://docs.google.com/presentation/d/1BNrdSU1fcYsMhCy-Zi0Opf7WSnPZTtiVFwop8F1gSQY/pub?start=false&loop=false&delayms=3000
1+
Slides on pdb, the python debugger, are at https://docs.google.com/presentation/d/1BNrdSU1fcYsMhCy-Zi0Opf7WSnPZTtiVFwop8F1gSQY/pub?start=false&loop=false&delayms=3000
2+
The slides on lambda functions are at https://docs.google.com/presentation/d/1GMMrDXzYFMFRn9ufrVUGb0vSBGO7VkV6GLAdu46CVzA/pub?start=false&loop=false&delayms=3000
3+
4+

week-02/sort_lambda.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#! /usr/bin/env python
2+
#
3+
# This program demonstrates the use of the lambda function to sort a list of
4+
# tuples
5+
#
6+
#
7+
my_list = [('one',2,['eggs','cheese']),
8+
('seventeen',17,['oregano','paparika']),
9+
('six',6,['steak','lobster']),
10+
('twelve',12,['beer','soda'])]
11+
12+
print "Before", my_list
13+
my_list.sort(key=lambda x: x[1])
14+
print "\nAfter", my_list
15+
16+
17+

0 commit comments

Comments
 (0)