I am trying to compare elements in two lists. Both of the lists contain numbers and are sorted from greatest to least. I want to find the list with the highest number. If they contain the same highest number, I want to look at the next highest number, etc.
So if I had a list: [14, 5, 4, 3, 2]
And I was comparing it to: [14, 7, 4, 3, 2]
The second list would be bigger because the next highest number is a 7.
Likewise, if I had a list: [13, 12, 9, 7, 3]
And: [13, 12, 9, 8, 2]
The second would again be the larger of the two.
Any help would be appreciated!
I tried one of these suggestions:
def compare_high_card(hand_a,hand_b): ''' Determines which hand has the highest high-card, returns 1 if hand_a has higher card, -1 if hand_b has higher_card :param hand_a: The first hand to compare :param hand_b: The second hand to compare :return: 1 if hand_a has higher card, -1 if hand_b has higher_card '''
hand_a = sort_hand_by_value(hand_a)
hand_b = sort_hand_by_value(hand_b)
hand_length = 5
for index in range(hand_length):
if hand_a[index] > hand_b[index]:
higher_hand = 1
break
elif hand_b[index] > hand_a[index]:
higher_hand = -1
break
else:
higher_hand = 0
return higher_hand
hand_a = [14, 9, 4, 3, 2] hand_b = [14, 8, 5, 3, 2]
This code only prints out -1.