Python crash course Flashcards
How to perform float division python
from __future__ import this
What is mutable? Give a definition alternative
Mutable: once you set it , cant modify it . Lists vs Sets
functions to present intrinsic elements of dictionaries
dict. values()
dict. keys()
dict. items #return the dict elements as a tuple
What is counter from collections?
For a data structure, it counts how many times an element appears.
Why to use sets?
Fast operations and checking membership
Difference between sorted(list_) and list_.sort()
The second is in place sorting
How to create function factories?
from functool import partial
new_func=partial(func,value=value_)
What map function performs?
maps(func,iterable) is the signature of the function.
According to func, it transforms the iterable which may be anything.
What does filter does
filter(func,iterable)
if func, which acts to the subsequent elements of an iterable, returns a true value then the element is kept.
Which is the functionality of zip(list1,list2)?
Merges two lists
What is ‘reduce’ function in python and how it is called?
The reduce() function accepts a function and a sequence and returns a single value calculated as follows:
Initially, the function is called with the first two items from the sequence and the result is returned. The function is then called again with the result obtained in step 1 and the next value in the sequence. This process keeps repeating until there are items in the sequence.
reduce(func, iterable)
Find minimum and maximum value of a list
min(list) max(list)
What is dispersion? Define a simple measure in python
Dispersion is a metric how spread are our data. A simle metric for a list of data is range def range(list_): return max(list_) -min(list_)
Describe a more complicated version of dispresion
A more complicated method of dispersion is variance
If you want to generate random events in python, you can use random module. Define two use cases
import random
random. randint(x,y) #produce a random int between x and y
random. choice(iterable) #produce a random element from the iterable