I have the following code:
for i in range(w[n], W):
array[n][i] = v[n]
In python this give an out of index error because I am not using append…how would I right the above in order to work in python???
All help will be appreciated! Thank You!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all, you shouldn’t use the name ‘array’ for an array. Even though it’s not a reserved name in python, it’s considered bad programming practice. A way to do what you want is like this:
The first line creates an array of [n][W] elements initialized to 0. It’s the easiest way to achieve this in python without adding an extra dependency.