new files

This commit is contained in:
Ingy döt Net 2013-04-10 12:38:42 -07:00
parent 3af7344581
commit 86c034bb8b
1364 changed files with 21352 additions and 0 deletions

View file

@ -0,0 +1,7 @@
haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]
for needle in ("Washington","Bush"):
try:
print haystack.index(needle), needle
except ValueError, value_error:
print needle,"is not in haystack"

View file

@ -0,0 +1,9 @@
>>> haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]
>>> haystack.index('Bush')
4
>>> haystack.index('Washington')
Traceback (most recent call last):
File "<pyshell#95>", line 1, in <module>
haystack.index('Washington')
ValueError: list.index(x): x not in list
>>>

View 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"
>>>