Ad

Monday, December 11, 2017

Finding Repeats in an Array or a List - Technical Interview in Python Patterns

Practice using Hash map.

def find_repeat(numbers):
seen = set()
for n in numbers:
if n in seen:
return n
else:
seen.add(n)
return False #if no duplicate found

Instead of returning False, you can also raise an exception. Use this:
raise Exception('custom exception message here')

No comments:

Post a Comment

Codecademy - Machine Learning Fundamentals - Syllabus

Upgrade your skills with Codecademy's Pro Intensive, Machine Learning Fundamentals. Each unit will cover conceptual and syntax lessons ...