import PrintHelper
import itertools
PrintHelper.PrintCode('import itertools')
PrintHelper.PrintTitle('itertools Module')
PrintHelper.PrintHint('itertools,一个模块用以iterators的操作')
PrintHelper.PrintSubtitle('方法集合')
PrintHelper.PrintSampleWithDescription('chain(@iterable[,@iterable])','允许像迭代一个对象一样迭代多个iterable的集合')
PrintHelper.PrintSampleWithDescription('zip_longest()','与zip()方法相似,但是它创建了一个迭代器,它以其中最长的数据长度为准,而zip()以最短的为准')
PrintHelper.PrintSampleWithDescription('product(@iterable[,@iterable])','乘积,笛卡尔积')
PrintHelper.PrintSampleWithDescription('permutations(@iterable[,@length])','置换组合(均匀排列组合),考虑排列,指定个数对可迭代的数据作排列组合.Anm Cnm')
PrintHelper.PrintSampleWithDescription('combinations(@iterable[,@length])','组合,忽视排列')
PrintHelper.PrintSampleWithDescription('combinations_with_replacement(@iterable[,@length])','组合,非均匀排列组合')
PrintHelper.PrintHint('chain(@iterable[,@iterable])','允许像迭代一个对象一样迭代多个iterable的集合')
PrintHelper.PrintCode('seq = itertools.chain( [1,2,3], [11,12,13,14], [x*x for x in range(1,6)] )')
PrintHelper.PrintCode('for item in seq:')
PrintHelper.PrintCode('    print( item, end=\" \")')
seq = itertools.chain( [1,2,3], [11,12,13,14], [x*x for x in range(1,6)] )
for item in seq:
    print( item, end=" ")
PrintHelper.PrintHint('zip_longest()','与zip()方法相似,但是它创建了一个迭代器,它以其中最长的数据长度为准,而zip()以最短的为准')
PrintHelper.PrintCode('seq = itertools.zip_longest( \"apple\", \"strawberry\", \"banana\", fillvalue=\" \")')
PrintHelper.PrintCode('for item in seq:')
PrintHelper.PrintCode('    print( item )')
seq = itertools.zip_longest( "apple", "strawberry", "banana", fillvalue=" ")
for item in seq:
    print( item )
PrintHelper.PrintHint('product()','product(),乘积')
PrintHelper.PrintCode('seq = itertools.product( [1,2,3], \"ABC\", [\"apple\",\"banana\"] )')
PrintHelper.PrintCode('for item in seq:')
PrintHelper.PrintCode('    print( item )')
seq = itertools.product( [1,2,3], "ABC", ["apple","banana"] )
for item in seq:
    print( item )
PrintHelper.PrintHint('permutations(@iterable[,@count])','排列,指定个数对可迭代的数据作排列组合.Anm Cnm')
PrintHelper.PrintCode('seq = itertools.permutations( [1,2,3], 2 )')
PrintHelper.PrintCode('for item in seq:')
PrintHelper.PrintCode('    print( item )')
seq = itertools.permutations( [1,2,3], 2 )
for item in seq:
    print( item )
PrintHelper.PrintHint('combinations(@iterable[,@length])','组合,忽视排列')
PrintHelper.PrintCode('seq = itertools.combinations( [1,2,3], 2 )')
PrintHelper.PrintCode('for item in seq:')
PrintHelper.PrintCode('    print( item )')
seq = itertools.combinations( [1,2,3], 2 )
for item in seq:
    print( item )
PrintHelper.PrintHint('combinations_with_replacement(@iterable[,@length])'
                      ,'组合,非均匀排列组合,跟permutation结果相似,但是其为不均匀组合')
PrintHelper.PrintCode('seq = itertools.combinations_with_replacement( [1,2,3], 2 )')
PrintHelper.PrintCode('for item in seq:')
PrintHelper.PrintCode('    print( item )')
seq = itertools.combinations_with_replacement( [1,2,3], 2 )
for item in seq:
    print( item )
