I am setting a variable to the ith element of the list, but I am getting out of range error even in the first iteration.
# code the max() function
def maxinlist(yourlist):
first = 0
second = 0
duplicatelist = yourlist
for i in range(0, len(yourlist) - 1):
first = yourlist[i]
for j in range(len(yourlist) - 1, 0, -1):
second = yourlist[j]
if second > first:
duplicatelist.pop(i)
elif first > second:
duplicatelist.pop(j)
print(duplicatelist[0])
mylist = [1, 4, 8, 2, 5, 100, 44, 2, 5]
maxinlist(mylist)