I tried to run this code, but it showed an error:
def shoot(aliens):
s=[0]*1000
s[0]=0
s[1]=1
num=len(aliens)
b=[[0 for m in range(1000)] for n in range(1000)]
for j in xrange(2,num):
for i in xrange(0,j):
b[j][i]=s[i]+min(int(aliens[j]),f[j-i]) ##Error here
s[j]=max(b)
and the error:
Traceback (most recent call last):
File "module1.py", line 67, in <module>
print shoot(line)
File "module1.py", line 26, in shoot
b[j][i]=s[i]+min(int(aliens[j]),f[j-i])
TypeError: can only concatenate list (not "int") to list
please help!
Edit: added more code. s, aliens and f are other arrays. I tried to save the result to the 2 dimentional array, but it showed that error.
s[j] = max(b)
doesn't treat b
as a 2-d array of integers and pick the biggest one. b
is a list of lists. max(b)
compares the lists and returns the one that compares highest. (List comparison is done by comparing the elements lexicographically.)
You want
s[j] = max(max(sublist) for sublist in b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With