Define first-class object
An entity within a programming language that can:
What do we know about functions in python? (1)
They’re first-class objects
What are the features of functional programming? (4)
What are the advantages of functional programming? (4)
Modularity
Composability
Ease of testing and debugging
Formal provability
What’s the syntax for generator comprehension?
Same as list comprehension but with parentheses
Describe lazy vs eager evaluation. Which is used by most languages?
What are you doing when you make a generator?
Make the function able to be used as an iterator
What happens when yield is executed? (4)
What is an infinite generator? Give an example of this.
What does map do? (2)
What are the args of filter? What does it return?
What are the different callables? (6)
What is currying?
the process of converting a multi-argument function into a chain of single-argument function applications is called “currying”,
Describe the idea of a python closure
Describe chain() from itertools (1)
chain together multiple iterators
What does tee from itertools do?
split an iterator into two lazily-evaluated copies
What does cycle from itertools do?
– cycle(): endlessly cycle through the elements of an iterable
What does dropwhile from itertools do?
skip elements of an iterable until the first time a predicate
becomes false
What does groupby from itertools do?
create sub-iterators grouped by the value of a keygen function
What does partial from functools do?
return an object that behaves like a partially-applied function
● similar to currying
What does wraps from functools do?
used to create function decorators like @staticmethod
How do you sort a list in python?
Has a .sort() method which sorts it in place.
How do you sort an iterable in python (two different argument sets)
result = sorted(iterable)
result = sorted(iterable,key,reverse)
● ‘key’ is a function which returns a sorting key
● ‘reverse’ is a boolean; if True, sort in descending order