Map, Filter & Lambda Function Flashcards

1
Q

A built in function in Python that allows you to process and transform all the items in an iterable w/o using an explicit for loop, a technique commonly known as (blank-ing)

A

map()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you map a function to a sequence?

def moneytone in seq

A

map(moneytone,seq)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How would you pass this map function into a list?

map(moneytone,seq)

A

list(map(moneytone,seq))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Consists of applying a predicate or Boolean-valued function to an iterable to generate a new iterable

A

Filtering

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A lambda expression takes in a number and returns a condition T or F value based on the conditional operation

list(filter(lambda num: num*2 == 0,seq))

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

m = ‘ I Am The Greatest’

m.upper()

m.lower()

m.split()

What are these called

A

All uppercase

All lowercase

Splits a string on all the white spaces of that a string

Methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you get the keys items and values of a dictionary?

m = {‘X1’ : 5, ‘X2’ : 8}

A

m.keys() [‘X1’ , ‘X2’]
m.items() [(‘X1’, 5), (‘X2’,8)])
m.values() [5,8]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Do dictionaries contain an order?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Use lambda exp and filter function to filter out the words from a list that don’t start with the letter ‘s’. For example:

www = [‘soup’, ‘dog’, ‘monkey, ‘dollar’, ‘salad’]

A

list(filter(lambda word: word[0]==‘s’ ,www))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly