new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
13
Task/Search-a-list/Python/search-a-list-3.py
Normal file
13
Task/Search-a-list/Python/search-a-list-3.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
>>> def hi_index(needle, haystack):
|
||||
return len(haystack)-1 - haystack[::-1].index(needle)
|
||||
|
||||
>>> # Lets do some checks
|
||||
>>> for n in haystack:
|
||||
hi = hi_index(n, haystack)
|
||||
assert haystack[hi] == n, "Hi index is of needle"
|
||||
assert n not in haystack[hi+1:], "No higher index exists"
|
||||
if haystack.count(n) == 1:
|
||||
assert hi == haystack.index(n), "index == hi_index if needle occurs only once"
|
||||
|
||||
|
||||
>>>
|
||||
Loading…
Add table
Add a link
Reference in a new issue