Pyextend Library-unpack List Collection string unpacking function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.