【小卒python】中itertools.product的的详解、用法

class product(object):
    """
    product(*iterables, repeat=1) --> product object
    
    Cartesian product of input iterables.  Equivalent to nested for-loops.
    
    For example, product(A, B) returns the same as:  ((x,y) for x in A for y in B).
    The leftmost iterators are in the outermost for-loop, so the output tuples
    cycle in a manner similar to an odometer (with the rightmost element changing
    on every iteration).
    
    To compute the product of an iterable with itself, specify the number
    of repetitions with the optional repeat keyword argument. For example,
    product(A, repeat=4) means the same as product(A, A, A, A).
    
    product('ab', range(3)) --> ('a',0) ('a',1) ('a',2) ('b',0) ('b',1) ('b',2)
    product((0,1), (0,1), (0,1)) --> (0,0,0) (0,0,1) (0,1,0) (0,1,1) (1,0,0) ...
    """

类产品(对象):
”“”
product(*iterables, repeat=1)——> product对象

输入迭代的笛卡尔积。相当于嵌套的for循环。

例如,product(A, B)对于A中的x和B中的y,返回的结果是相同的:((x,y)
最左边的迭代器在最外面的for循环中,因此输出元组
以类似里程表的方式循环(最右边的元素改变)
在每次迭代)。

要计算与自身的可迭代的乘积,请指定数字
使用可选的repeat关键字参数重复的。例如,
product(A, repeat=4)的含义与product(A, A, A, A)相同。

产品(“ab”范围(3))- - >(' a ',0)(' a ',1)(' a ',2)(' b ',0)(' b ',1)(' b ',2)
产品((0,1),(0,1),(0,1))- - >(0,0,0)(0,0,1)(0,1,0)(0,1,1)(1,0,0)…
”“”

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值