arrays - Updating values inside a list comprehension -


i wondering whether possible update values inside list comprehension.

i thinking of like:

a = [1,2] b = [3,1,0] ans = [0]*(n+m-1) print [ans[i+j] += a[i]*b[j] in xrange(len(a)) j in xrange(len(b))] 

short answer: no. comprehension list provides concise way create lists.

in case though, still use comprehension list create list (not update it):

a = [1,2] b = [3,1,0] ans = [sum((a[i]* b[s-i] in range(max(0, s-len(b)+1), min(len(a),s+1)))) s in range(len(a)+len(b)-1)] print ans 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -