So in this exercise we need to create a function named more_frequent_item
that has three parameters named lst
, item1
, and item2
.
Return either item1
or item2
depending on which item appears more often in lst
.
If the two items appear the same number of times, return item1
.
and this is what i get so far:
def more_frequent_item(lst, item1, item2):
total1 = lst.count(item1)
total2 = lst.count(item2)
if total1 == total2:
print(item1)
else:
print(item2)
print(more_frequent_item([2, 3, 3, 2, 3, 2, 3, 2, 3], 2, 3))
but is giving me Syntax Error, and i don’t kow why. I’m a novice programmer, so i think this is simple, but i can’t get it. Sorry and thank you.