9e1e8cd642
Also modify mp_get_index to accept: 1. Indices that are or evaluate to a boolean. 2. Slice indices. Add tests for these two cases.
35 lines
597 B
Python
35 lines
597 B
Python
a = [1, 2, 3]
|
|
print(a.index(1))
|
|
print(a.index(2))
|
|
print(a.index(3))
|
|
print(a.index(3, 2))
|
|
print(a.index(1, -100))
|
|
print(a.index(1, False))
|
|
|
|
try:
|
|
print(a.index(1, True))
|
|
except ValueError:
|
|
print("Raised ValueError")
|
|
else:
|
|
print("Did not raise ValueError")
|
|
|
|
try:
|
|
print(a.index(3, 2, 2))
|
|
except ValueError:
|
|
print("Raised ValueError")
|
|
else:
|
|
print("Did not raise ValueError")
|
|
|
|
a = a + a
|
|
b = [0, 0, a]
|
|
print(a.index(2))
|
|
print(b.index(a))
|
|
print(a.index(2, 2))
|
|
|
|
try:
|
|
a.index(2, 2, 2)
|
|
except ValueError:
|
|
print("Raised ValueError")
|
|
else:
|
|
print("Did not raise ValueError")
|