mirror of
https://github.com/ossu/computer-science.git
synced 2024-10-01 01:26:01 -04:00
search pattern in 1.1.3
This commit is contained in:
parent
575e44c837
commit
4570e40f5c
Binary file not shown.
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user