I am new to this world and I am starting to take my first steps in python. I am trying to extract in a single list the indices of certain values of my list (those that are greater than 10). When using append I get the following error and I don't understand where the error is.
dbs = [0, 1, 0, 0, 0, 0, 1, 0, 1, 23, 1, 0, 1, 1, 0, 0, 0,
1, 1, 0, 20, 1, 1, 15, 1, 0, 0, 0, 40, 15, 0, 0]
exceed2 = []
for d, i in enumerate(dbs):
if i > 10:
exceed2.append= (d,i)
print(exceed2)
You probably mean to write
Few fixes here:
append=()is invalid syntax, you should just writeappend()i, dvalues fromenumerate()are returning the values and indexes. You should be checkingd > 10, since that's the value (per your description of the task). Then you should be putting onlyiinto theexceed2array. (I switch theianddvariables so thatiis forindexas that's more conventional)append(d,i)wouldn't work anyway, asappendtakes one argument. If you want to append both the value and index, you should use.append((d, i)), which will append a tuple of both to the list.exceed2every time the condition is hit, when you could just print it once at the end.