2014-05-25 20:12:56 +01:00
|
|
|
x = list(range(10))
|
|
|
|
print(x[::-1])
|
|
|
|
print(x[::2])
|
|
|
|
print(x[::-2])
|
2014-05-25 20:17:06 +01:00
|
|
|
|
|
|
|
x = list(range(9))
|
|
|
|
print(x[::-1])
|
|
|
|
print(x[::2])
|
|
|
|
print(x[::-2])
|
2016-10-30 16:25:04 +00:00
|
|
|
|
|
|
|
x = list(range(5))
|
|
|
|
print(x[:0:-1])
|
|
|
|
print(x[:1:-1])
|
|
|
|
print(x[:2:-1])
|
|
|
|
print(x[0::-1])
|
|
|
|
print(x[1::-1])
|
|
|
|
print(x[2::-1])
|
|
|
|
|
|
|
|
x = list(range(5))
|
|
|
|
print(x[0:0:-1])
|
|
|
|
print(x[4:4:-1])
|
|
|
|
print(x[5:5:-1])
|
|
|
|
|
|
|
|
x = list(range(10))
|
|
|
|
print(x[-1:-1:-1])
|
|
|
|
print(x[-1:-2:-1])
|
|
|
|
print(x[-1:-11:-1])
|
|
|
|
print(x[-10:-11:-1])
|
2017-05-17 07:33:57 +01:00
|
|
|
print(x[:-15:-1])
|
|
|
|
|
|
|
|
# test negative indices that are out-of-bounds
|
|
|
|
print([][::-1])
|
|
|
|
print([1][::-1])
|
|
|
|
print([][0:-10:-1])
|
|
|
|
print([1][0:-10:-1])
|
|
|
|
print([][:-20:-1])
|
|
|
|
print([1][:-20:-1])
|
|
|
|
print([][-20::-1])
|
|
|
|
print([1][-20::-1])
|