You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
723 B
44 lines
723 B
# test the builtin reverse() function
|
|
try:
|
|
reversed
|
|
except:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
# list
|
|
print(list(reversed([])))
|
|
print(list(reversed([1])))
|
|
print(list(reversed([1, 2, 3])))
|
|
|
|
# tuple
|
|
print(list(reversed(())))
|
|
print(list(reversed((1, 2, 3))))
|
|
|
|
# string
|
|
for c in reversed('ab'):
|
|
print(c)
|
|
|
|
# bytes
|
|
for b in reversed(b'1234'):
|
|
print(b)
|
|
|
|
# range
|
|
for i in reversed(range(3)):
|
|
print(i)
|
|
|
|
# user object
|
|
class A:
|
|
def __init__(self):
|
|
pass
|
|
def __len__(self):
|
|
return 3
|
|
def __getitem__(self, pos):
|
|
return pos + 1
|
|
for a in reversed(A()):
|
|
print(a)
|
|
|
|
# user object with __reversed__
|
|
class B:
|
|
def __reversed__(self):
|
|
return [1, 2, 3]
|
|
print(reversed(B()))
|
|
|