blade.xslice¶
blade slicing operations
- blade.xslice.xat(iterable, n, default=None)¶
Slice off items in iterable found at index n.
Parameters: Returns: iterator of items
>>> from blade.xslice import xat >>> # default behavior >>> xat([5, 4, 3, 2, 1], 2) 3 >>> # return default value if nothing found at index >>> xat([5, 4, 3, 2, 1], 10, 11) 11
- blade.xslice.xchoice(iterable)¶
Randomly slice off one items in iterable.
Parameters: iterable – iterable >>> from blade.xslice import xchoice >>> list(xchoice([1, 2, 3, 4, 5, 6])) 3
- blade.xslice.xdice(iterable, n, fill=None)¶
Slice one iterable items in iterable into n iterable items in iterable.
Parameters: Returns: iterator of items
>>> from blade.xslice import xdice >>> list(xdice(['moe', 'larry', 'curly', 30, 40, 50, True], 2, 'x')) [('moe', 'larry'), ('curly', 30), (40, 50), (True, 'x')]
- blade.xslice.xfirst(iterable, n=0)¶
Slice off n things from the starting end of iterable or just the first items in iterable.
Parameters: Returns: iterator of items
>>> from blade.xslice import xfirst >>> # default behavior >>> list(xfirst([5, 4, 3, 2, 1])) [5] >>> # first things from index 0 to 2 >>> list(xfirst([5, 4, 3, 2, 1], 2)) [5, 4]
- blade.xslice.xinitial(iterable)¶
Slice off every items in iterable except the last iterable.
Parameters: iterable – iterable Returns: iterator of items >>> from blade.xslice import xinitial >>> list(xinitial([5, 4, 3, 2, 1])) [5, 4, 3, 2]
- blade.xslice.xlast(iterable, n=0)¶
Slice off n things from the tail end of items in iterable or just the last items in iterable.
Parameters: Returns: iterator of items
>>> from blade.xslice import xlast >>> # default behavior >>> list(xlast([5, 4, 3, 2, 1]))[0] 1 >>> # fetch last two things >>> list(xlast([5, 4, 3, 2, 1], 2)) [2, 1]