mirror of
https://github.com/ossu/computer-science.git
synced 2025-02-25 00:49:51 -05: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]
|
total += items[i]
|
||||||
return total
|
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…
x
Reference in New Issue
Block a user