Python中的itertools.product(关键词:itertools/product)
2018-02-24 20:45
519 查看
product(A, B)函数,返回A、B中的元素的笛卡尔积的元组。听起来有点绕,先看代码吧:
product(list1, list2) 依次取出list1中的每1个元素,与list2中的每1个元素,组成元组,
然后,将所有的元组组成一个列表,返回。
参考文献:
1. Python itertools模块详解;
2. itertools.product - Python标准库。
>>> import itertools >>> itertools.product([1,2,3],[100,200]) <itertools.product object at 0x7f3e6dd7bc80> >>> for item in itertools.product([1,2,3],[100,200]): ... print item ... (1, 100) (1, 200) (2, 100) (2, 200) (3, 100) (3, 200)
product(list1, list2) 依次取出list1中的每1个元素,与list2中的每1个元素,组成元组,
然后,将所有的元组组成一个列表,返回。
参考文献:
1. Python itertools模块详解;
2. itertools.product - Python标准库。
相关文章推荐
- Python小技巧:使用*解包和itertools.product()求笛卡尔积
- python中itertools里的product和permutation
- Python中的itertools.permutations(关键词:itertools/permutations)
- Python:itertools模块 combinations和product的使用
- Python HackerRank|Maximize It!(from itertools import product)
- python itertools.product的用法
- Python:itertools模块 combinations和product的使用
- Python小技巧:使用*解包和itertools.product()求笛卡尔积
- Python中的itertools.combinations(iterable, r)(关键词:itertools/combinations)
- Python 过滤字符串的技巧,map与itertools.imap
- 详解Python中的分组函数groupby和itertools)
- python itertools
- python itertools
- python中itertools模块zip_longest函数详解
- python itertools和迭代器的使用
- python 排列组合之itertools
- Python中itertools模块用法详解
- Python itertools模块
- python itertools的函数(含有排列组合函数)
- python itertools的使用