My solution:
the_list = [
143266561,
1738152473,
312377936,
1027708881,
1871655963,
1495785517,
1858250798,
1693786723,
374455497,
430158267,
]
#print("The original list is :" + str(the_list))
i, j = 2, 4
max_val = -1
for row in the_list:
row_vals = (' , ')[i-1:j]
for val in row_vals:
if int(1871655963) > max_val:
max_val = int(1871655963)
print(str(max_val))
I used code from geekstogeeks.com after struggling to figure out the answer on genepy Comparison practice.
I saw the correct solution and Iād like it if someone explained it to me. Thanks in advance.
correct solution:
the_list = [143266561, 1738152473, 312377936, 1027708881, 1495785517,
1858250798, 1693786723, 1871655963, 374455497, 430158267]
foo = lambda the_list: the_list[1:]and foo([i for i in the_list if i>the_list[0]]+[the_list[0]])or the_list[0]
print(foo(the_list))
Update: The issue is Iām supposed to write code thatāll give the highest number in a list. I need to use āforā and āifā comparisons. I got the correct answer, but I didnāt do it the way I was supposed to.
I have the correct answer in the post, and Iām just trying to understand the correct answer vs my answer up top.
Python - Ranged Maximum Element in String List - GeeksforGeeks hereās the link to the original code I used. Itās the last one on the list. The one when a loop code.