data = [(1, 2)]
for n, (x, y) in enumerate(data):
print(n, x, y)
Задачи по питону и машинному обучению: алгоритмы, функции, классы, регулярные выражения, итераторы, генераторы, ООП, исключения, numpy, pandas, matplotlib, scikit-learn, TensorFlow и др. #Python #ml
data = [(1, 2)]
for n, (x, y) in enumerate(data):
print(n, x, y)data = [(1, 2)]
for n, x, y in enumerate(data):
print(n, x, y, end=" ")my_list = ['a', 'b']
for idx, val in enumerate(my_list, 3):
print(idx, val, end=" ")items = ['a', 'b', 'c'] from itertools import combinations_with_replacement p = len([* combinations_with_replacement(items, 2)]) print(p)
items = ['a', 'b', 'c'] from itertools import combinations p = len([*combinations(items, 2)]) print(p)
items = ['a', 'b', 'c'] from itertools import permutations p = len([*permutations(items, 2)]) print(p)
from itertools import dropwhile s = [x for x in dropwhile(lambda t: t % 2 == 0, [10, 8, 6, 5, 4, 3])] print(*s)
from itertools import dropwhile s = [x for x in dropwhile(lambda t: t % 2 == 0, range(4))] print(*s)
from itertools import islice
items = [1, 2, 3, 4, 5, 6]
for x in islice(items, 3, None):
print(x, end="")from itertools import islice g = (i**2 for i in range(1, 4)) print(*g[1:3]) # 1 print(*islice(g, 1, 3)) # 2 print(*slice(g, 1, 3)) # 3 print(*g.slice(1, 3)) # 4
from itertools import repeat, chain
class A:
def __init__(self, x):
self.x = x
def __reversed__(self):
return chain(reversed(self.x), repeat(0, 2))
a = A([1, 2])
print(*reversed(a))class X:
def __init__(self, arr):
self._arr = arr
def __iter__(self):
return reversed(self._arr)
x = X([1, 2, 3])
for i in x:
print(i, end=" ")