Python Basics IV Functions, Map, and Lambda Flashcards

1
Q

How do you create a function in Python

A

use def, a colon, then indent.

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

What is map used for?

A

A code convenience, it makes it easy to apply a function to all the elements of a list.

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

What is lamda for?

A

To streamline code, you basically need function, but it’s a one shot deal, so you woud like to avoid the overhead required to construct a proper function.

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

Can you write a function on a single line. (So there would be no indenting)?

A

Yes

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

Map applies a function (or lambda expression) to every element in a list. FILTER works similarly, but applies a filter to every element in a sequence. Using filter, write an expression that would only return the even number from a list of numbers.?

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

What does the split method do?

A

You can apply it to a string, it will create a list where each element between the blanks shows.
Suppose, for example we wanted to extract the tag in a tweet. It would be done as shown.

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

What are the 2 important dictionary methods?

A

.keys and .values
A dictionary is a collection of key/value pairs.

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

Does a Python list have a Push and Pop method?

A

No, it has Append and Pop methods. Those methods have an optional integer argument. The default value is 0.

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

What method returns a boolean to determine if an item is in a list.

A

The “in” method

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

What is tuple unpacking

A

It is a shortcut method for extracting items from tuples when you have a list of tuples.

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