Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bisect
- l = [(5, 100), (15, 200), (20, 300)]
- # --------------------
- x = bisect.bisect(l, (10, None))
- print x, "Falsch, ich will 0"
- # --------------------
- x = bisect.bisect(l, (10, None))-1
- print x, "Richtig, ich will 0"
- # --------------------
- x = bisect.bisect(l, (10, None))
- if x > 0:
- x -= 1
- print x, "Richtig, inkl. special case handling für 0. index"
- # --------------------
- x = bisect.bisect(l, (15, None))
- if x > 0:
- x -= 1
- print x, "falsch, ich will 1. Problem ist, dass (15, None) < (15, 200) ist."
- # --------------------
- t = 15
- x = bisect.bisect(l, (t, None))
- if x < len(l) and l[x][0] == t:
- pass
- elif x > 0:
- x -= 1
- print x, "richtig, mit Test für genauer Zeittreffer (exception handling letzer Wert im array)"
- # --------------------
- def getValue(l, t):
- x = bisect.bisect(l, (t, None))
- if x < len(l) and l[x][0] == t:
- pass
- elif x > 0:
- x -= 1
- return x
- # --------------------
- print "----- tests -----"
- for i in range(25):
- print i, "=", l[getValue(l, i)][1], "(index:", getValue(l, i), ")"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement