search pattern in 1.1.3

This commit is contained in:
Eric Douglas 2014-05-22 19:03:36 -03:00
parent 575e44c837
commit 4570e40f5c
2 changed files with 18 additions and 0 deletions

View File

@ -33,4 +33,22 @@ def sumEvens(items):
total += items[i]
return total
# The search pattern
def find(target, items): # is target in items?
return occurrences(target, items) > 0
def occurrences(target, items):
count = 0
for i in range(0, len(items), 1):
if items[i] == target:
count += 1
return count
## search with short-circuit
def find(target, items):
for i in range(0, len(items), 1):
if items[i] == target:
return True
return False