python 来自http://echohiyang.coding.me/categories/

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 来自http://echohiyang.coding.me/categories/相关的知识,希望对你有一定的参考价值。

# encoding: utf-8
""" return 返回的是完整的结果
    yield 返回的是一个值"""


def myzip1(*seqs):
    """使用返回值"""
    seqs = [list(S) for S in seqs]
    res = []
    while all(seqs):
        res.append(tuple(x.pop(0) for x in seqs))
    return res


def myzip2(*seqs):
    """使用生成器"""
    seqs = [list(S) for S in seqs]
    # print(seqs)
    while all(seqs):
        yield tuple(x.pop(0) for x in seqs)


def myzip3(*seqs, pad=None):
    """使用返回值"""
    seqs = [list(S) for S in seqs]
    # print(seqs)
    res = []
    while any(seqs):
        res.append(tuple((x.pop(0) if x else pad) for x in seqs))
    return res


def myzip4(*seqs, pad=None):
    """使用生成器"""
    seqs = [list(S) for S in seqs]
    # print(seqs)
    while any(seqs):
        yield tuple((x.pop(0) if x else pad) for x in seqs)


def myzip5(*seqs):
    """使用计数器进行限制"""
    minlen = min([len(x) for x in seqs])
    return [tuple(S[i] for S in seqs) for i in range(minlen)]


def myzip6(*seqs, pad=None):
    """使用计数器进行限制"""
    maxlen = max(len(x) for x in seqs)
    return [tuple((S[i] if i < len(S) else pad) for S in seqs) for i in range(maxlen)]


# myzip1test = True
myzip1test = False
if __name__ == '__main__' and myzip1test:
    S1, S2 = 'abc', 'xyz123'
    print(myzip1(S1, S2))

# myzip2test = True
myzip2test = False
if __name__ == '__main__' and myzip2test:
    S1, S2 = 'abc', 'xyz123'
    print(list(myzip2(S1, S2)))

# myzip3test = True
myzip3test = False
if __name__ == '__main__' and myzip3test:
    S1, S2 = 'abc', 'xyz123'
    print(myzip3(S1, S2, pad=10))

# myzip4test = True
myzip4test = False
if __name__ == '__main__' and myzip4test:
    S1, S2 = 'abc', 'xyz123'
    print(list(myzip4(S1, S2, pad=10)))

# myzip5test = True
myzip5test = False
if __name__ == '__main__' and myzip5test:
    S1, S2 = 'abc', 'xyz123'
    print(myzip5(S1, S2))

# myzip6test = True
myzip6test = False
if __name__ == '__main__' and myzip6test:
    S1, S2 = 'abce', 'xyz123'
    print(myzip6(S1, S2))

以上是关于python 来自http://echohiyang.coding.me/categories/的主要内容,如果未能解决你的问题,请参考以下文章

python 来自Python的os文件系统

一封来自“Python”的信

来自 Black Hat Python 书的 Python 嗅探

“路径 python3(来自 --python=python3)不存在”错误

python Python装饰模板(来自“Head First Python ed.2”)

来自嵌套字典的 Python 数据类