Commit d9980a5f authored by Samarth Joshi's avatar Samarth Joshi

Koi review karo ise, poora time isme hi gya

parent acf87d55
import itertools as it
# import operator as op
import operator as op
""" def myFunc(deg, vals, coeffs):
for index in it.count():
if index > deg:
break
key = "x*" * (deg-index) + "y*" * (index) """
def myFunc(deg, vals, coeffs):
## write your code here
\ No newline at end of file
list1 = it.combinations_with_replacement(vals, deg)
list2 = it.combinations_with_replacement('xy', deg)
list3 = it.zip_longest(coeffs, list1, list2)
for coeff, values, keys in list3:
values_c = it.chain([coeff], values)
accv = it.accumulate(values_c, op.mul)
sliced_value = it.islice(accv, deg, deg+1)
keys_c = it.accumulate(keys, lambda x,y: x + "*" + y)
sliced_key = it.islice(keys_c, deg-1, deg)
merge = it.zip_longest(sliced_key, sliced_value)
result = it.starmap(lambda x,y: x + " --> " + str(y), merge)
yield from result
""" deg = 7
vals = [2,3]
coeffs = [4, 3, 5, 9, 3, 7, 2, 5]
gen = myFunc(deg, vals, coeffs)
for i in gen:
print(i) """
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment