 # Dragon Notes UNDER CONSTRUCTION
Latest content:
 Apr 05 Deep Learning Mar 19 Anomaly Detection - ML Mar 13 +Data Tables Mar 08 Clustering - Machine Learning Feb 28 Support Vector Machines - ML Feb 20 Regression - Data Science

# Python:Modules

itertools
- a standard library containing functions useful in functional programming
count(x,y) counts up infinitely from a value x, with an increment y
(= 1 default)

cycle infinitely iterates through an iterable (e.g. list or string)
repeat repeats an object, either infinitely or a specific # of times
takewhile - takes items from an iterable while a predicate function remains true
chain - combines several iterables into one long one
accumulate - returns a running total of values in an iterable
product - returns every possible combination of first and second input elems.
permutations - returns every possible combination of first's elements, in sets of second's val. (=1 default)
from itertools import count

for i in count(3):
print(i)
if i >=9:
break

>>> 3
4
5
6
7
8
9
from itertools import product, permutations

letters = ("A", "B", "C")
print(list(product(letters, range(2))))
print(list(permutations(letters, 1)))
print(list(permutations(letters, 2)))
print(list(permutations(letters, 3)))

>>> [('A', 0), ('A', 1), ('B', 0), ('B', 1), ('C', 0), ('C', 1)]
[('A',), ('B',), ('C',)]
[('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]
[('A', 'B', 'C'), ('A', 'C', 'B'), ...]

from itertools import acumulate, takewhile

nums = list(acumulate(range(8)))
print(nums)
print(list(takewhile(lambda x: x<= 6, nums)))

>>> [0, 1, 3, 6, 10, 15, 21, 28]
[0, 1, 3, 6]

Dragon Notes,   Est. 2018     About