Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn
https://telega.in/c/python_tasks
Questions — @dina_ladnyuk
Post #1374
2.3K
PY @python_tasks
Showing posts older than #1376 · Back to latest
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))