B=l.append((l[i]+A+B))
l is a list, and I'm trying to add more value to it so that it works like an array. But it still gives me an error, like a list index is out of range. How to get rid of it?
There are many problems in the code:
1) the method append does not return anything , so it makes no sense to writeB = l.append(...)
append
B = l.append(...)
2) The double bracket is confused, the code you wrote is exactly equivalent B.append(l[i]+A+B)
B.append(l[i]+A+B)
3) Finally, it is obvious that the index imust be a valid index for the list l, otherwise you will get an exception IndexError.
i
l
IndexError
, i , len(l) - 1 ( Python , 0 1, len(l) - 1, len(l).
len(l) - 1
len(l)
:
try: B = l.append((l[i] + A + B)) except IndexError: print "Appending from index", i, "to list l of length:", len(l) raise
i l, , .
? . , l, , i , , len(l) - 1.
The variable is igreater than or equal to the size of the array l.
Source: https://habr.com/ru/post/1740556/More articles:How to get the background color of an arbitrary image using MATLAB? - image-processingHow to automate padding for harsh images using MATLAB? - image-processingLibrary for converting latex to png to java - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1740554/convert-rgb-values-to-equivalent-hsv-values-using-python&usg=ALkJrhh8wiPAQhVG9YGVXF03qCM7iJ3rrADropdownlist binding using jquery - jqueryto determine if the chipset is able to disable packet injection mode and monitoring mode - linuxDisplay text in an image in Java - javaHow to handle your Internet connection in the GWT app - gwtCompiler: translation to assembly - assemblySaving a PHP script separately from the user interface - phpAll Articles