Python Data Science Tool Box -1 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Good to Remember : Tuples

A

Note that the return statement return x, y has the same result as return (x, y): the former actually packs x and y into a tuple under the hood!

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

How would you write a lambda function add_bangs that adds three exclamation points ‘!!!’ to the end of a string a?

How would you call add_bangs with the argument ‘hello’?

A

The lambda function definition is:

add_bangs = (lambda a: a + ‘!!!’),

and the function call is: add_bangs(‘hello’).

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

nums = [2, 4, 6, 8, 10]

result = map(lambda a: a ** 2, nums)

What does this piece of lambda code do?

A

You can see here that a lambda function, which raises a value a to the power of 2, is passed to map() alongside a list of numbers, nums. The map object that results from the call to map() is stored in result.

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

Whar does the map() do?

A

map() applies a function over an object, such as a list.

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

What does the filter () do?

A

The function filter() offers a way to filter out elements from a list that don’t satisfy certain criteria.

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

What are the 2 ways of raising an exception?

A

try : except:

and using raise

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