Pyextend-python Extend Lib
Unpack (iterable, Count, Fill=none)
Parameters:
Iterable: An iterative object that implements __ITER__, such as STR, tuple, dict, list
Count: The number that needs to be split, with an value greater than Len (iterable) followed by fill
Fill: Default Value padding
Examples of Use:
Example 1: in['abc' in[2]: A, B = unpack (source, 2) in[ Print(A, b) 2: in['abc' in[2]: A, B, c, d = unpack (source, 4) in[print(A, B, C, D) a B None none< /c22>
Code:
@accepts (iterable='__iter__', count=int)defUnpack (iterable, Count, fill=None):"""The ITER data unpack function. """iterable=List (Enumerate (iterable)) CNT= CountifCount <= Len (iterable)ElseLen (iterable) Results= [Iterable[i][1] forIinchrange (CNT)]#Results[len (Results): Len (results)] = [Fill for i in range (count-cnt)]Results = merge (results, [fill forIinchRange (count-CNT)]) returnTuple (results)
Pyextend Library-unpack List Collection string unpacking function