itertools in python
itertools.product()ΒΆ
Find out Cartesian product of input iterables.
In [9]:
itertools.permutations()ΒΆ
Return successive r-length permutations of elements in the iterable.
In [49]:
itertools.combinations()ΒΆ
Return successive r-length combinations of elements in the iterable.
In [34]:
itertools.combinations_with_replacement()ΒΆ
Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats.
In [35]:
In [54]:
Compress the String!ΒΆ
Make an iterator that returns consecutive keys and groups from the iterable.
In [62]:
In [48]:
123456789101112from itertools import product
k, m = list(map(int, input().split()))
# as the first element indicates the length of input, [1:] is used to give up that
num = [list(map(int, input().split()))[1:] for i in range(k)]
result = map(lambda x: sum(i**2 for i in x)%m, product(*num))
print(max(result))
itertools in python
Reviewed by Ikram
on
7/15/2021 04:41:00 PM
Rating:
No comments: