Control flow and functions Flashcards

1
Q

what is zip()?

A

zip() is used to combine 2 similar containers(list-list or dict-dict) printing the values sequentially. The loop exists only till the smaller container ends

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

what are the disadvantages of items() over iteritem() in dictanaroy?

A

It is very time-consuming.

It takes a lot of memory.

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

when we use yield?

A

We should use yield when we want to iterate over a sequence, but don’t want to store the entire sequence in memory.

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

what is generator unction?

A

A generator function is defined like a normal function, but whenever it needs to generate a value, it does so with the yield keyword rather than return. If the body of a def contains yield, the function automatically becomes a generator function.

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

when global keyword is needed in python function?

A

Global keyword is used inside a function only when we want to do assignments or when we want to change a variable. Global is not needed for printing and accessing.

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

what is first class function?

A

First class objects in a language are handled uniformly throughout. They may be stored in data structures, passed as arguments, or used in control structures

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

Properties of first class functions:

A

1 - A function is an instance of the Object type.
2 - You can store the function in a variable.
3 - You can pass the function as a parameter to another function.
4 - You can return the function from a function.
5 - You can store them in data structures such as hash tables, lists, …

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

what is memoizarion techinque?

A

Memoization is a technique of recording the intermediate results so that it can be used to avoid repeated calculations and speed up the programs. It can be used to optimize the programs that use recursion. In Python, memoization can be done with the help of function decorators.

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