Feedback on implementation of function which compares integer signs in Python.
- by John Magistr
Hi all.
I've made a small function which, given a tuple, compares if all elements in this tuple is of the same sign.
E.g., tuple = [-1, -4, -6, -8] is good, while [-1, -4, 12, -8] is bad. I am not sure I've made the smartest implementation, so I know this is the place to ask.
def check_consistent_categories(queryset):
try:
first_item = queryset[0].amount
if first_item < 0:
for item in queryset:
if item > 0:
return False
return True
else:
for item in queryset:
if item < 0:
return False
return True
except:
return False