For example I am looking for a way to search every spot in a list to see where an object is located. Some example psuedocode could go:
for every column in current row:
if column is the first one:
do this
if column in the last one:
do that
else:
find the previous row and columns place
Basically I am at a standstill so any insight would be helpful thanks
EDIT Sample Code:
for row in range(0,h+1):
newrow=[]
if row==0:
newrow=[1]
elif row==1:
newrow=[1,1]
else:
for column,x in enumerate(row):
if column==0:
newrow.append(1)
elif column==len(row)-1:
newrow.append(1)
else:
newrow.append(2)
Are you looking for
list.index?If you need special handling based on whether it’s the first or last item:
Or if you need to process all items anyway, consider using
enumerateto keep track of indices throughout the loop: