get_range
Get items using the range: [start, stop).
If stop is None, returns all remaining.
start and stop can be negative, similar to Python slicing:
-1is the tail-2is the node before the tail
Either or both start and stop can be negative/positive, but they must represent indices such that start < stop.
Returns
A list of node values. The list will be empty if:
- the range is invalid
start == stop
Examples
await list.create('list', type='str')
await list.add_head('list', ['A', 'B', 'C', 'D', 'E'])
print(await list.get_range('list', start=0))
print(await list.get_range('list', start=2))
print(await list.get_range('list', start=-2))
print(await list.get_range('list', start=1, stop=-2))
print(await list.get_range('list', start=-4, stop=-1))
# invalid: [3,1)
print(await list.get_range('list', start=-2, stop=1))
# invalid: [3,2)
print(await list.get_range('list', start=3, stop=-3))
Notes
The API performs simple checks on the ranges to spot problems before sending the query, but it's not always possible without knowing the list's size.
Consider the example above, this range is invalid:
But add two items and try again: