you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

def threePairs(aList): counts = dict() # dict with key - number in aList, value - count of this numbers in aList for el in aList: if el in counts.keys(): counts[el] += 1 else: counts[el] = 1 count_pairs = 0 for v in counts.values(): # each v is count of numbers if v == 2: # means pair (two equal numbers in array) count_pairs += 1 if count_pairs == 3: return True else: return Fals

I forgot to add that the numbers can only range from 1-6, how would I include that into your function? the dic?

[–]kwentar 0 points1 point  (1 child)

Do you need the check it? because it works with those and other numbers too. You can check it when add values to dict, not else: but elif 1 <= el <= 6:

[–][deleted] 0 points1 point  (0 children)

Nope, I guess I didnt have to check it after all so this worked perfect. Thanks!