A Rose by Any Other Name Invokes Just the Same - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

A Rose by Any Other Name Invokes Just the Same

Description:

Lambda. Functions as variables. Other cool and interesting stuff ... lambda. Lamba is an expression that return a function that returns a result ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 12
Provided by: Ada581
Category:
Tags: invokes | lambda | name | rose | same

less

Transcript and Presenter's Notes

Title: A Rose by Any Other Name Invokes Just the Same


1
A Rose by Any Other Name Invokes Just the Same
2
Whats up Doc?
  • This lecture is about functions
  • Lambda
  • Functions as variables
  • Other cool and interesting stuff

3
Functions are a special type of Variable
  • def a(x)
  • return x 1
  • b a
  • print b(x)
  • What did we get?

4
How do you invoke a function?
  • () operator
  • a
  • The function
  • a(5)
  • The result of calling a with the parameter 5

5
Why Does This Work?
  • MyDictionary "a" lambda x x1, "b" lambda
    x x-1
  • MyDictionary"a"(MyDictionary"b"(3))
  • 3

6
lambda
  • Lamba is an expression that return a function
    that returns a result
  • lamba parameters expression
  • lamba x x 1
  • b lamba x, y xy

7
Map()
  • Creates a new list after from the result of apply
    a function to each element of the list
  • y 1,2,3
  • x map(lambda z z1, y)
  • x 2,3,4
  • Can be use to merge multiple lists
  • z map(lambda a,b min(a,b), x,y)
  • y z

8
Zip()
  • Zip merges lists in a single list of tuples
  • D 1,2,3,4,5
  • E 10,11,12
  • zip(D,E) (1,10),(2,11),(3,12)
  • Zip return a list of len of the shortest list
    passed to it.

9
Reduce()
  • Takes a binary function and uses it to reduce a
    list to a single value
  • a 1,2, 3, 4
  • reduce(lambda r,l rl, a)
  • Sums the list

10
Filter
  • Return a new sequence that has been filtered by a
    conditional
  • filter(lambda x x 2 0, 1,2,3,4)

11
List Comprehension
  • expression for arg1 in sequence1 for argn in
    sequencen if condition
  • 2 s for s in range(10)
  • 2 s for s in range(10) if s 2 0
Write a Comment
User Comments (0)
About PowerShow.com