Python中文
首页
教程
问答
标签
搜索
登录
注册
将列表中的元素与listofList中的每个元素进行比较
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图将一个列表中的一个元素与列表列表中的每个元素进行比较。在</p> <pre><code>hsdr_machine_one=['P#1', 'P#2', ...] hsdr_machine_two=[...] hsdr_machine_three=[...] hsff_machine_four=['P#4', 'P#5', ...] hsff_machine_five=['P#6', ...] hsff_machine_six=[...] hsdr_machines_list=[hsdr_machine_one, hsdr_machine_two, hsdr_machine_three] hsff_machines_list=[hsff_machine_four, hsff_machine_five, hsff_machine_six] part_number_combinations = [] for part_number in itertools.product(*hsdr_machines_list): part_number_combinations = [part_number[0]] + [part_number[1]] print part_number_combinations </code></pre> <p>我知道这段代码不会把我带到那里,它只是我在<code>itertools</code>中瞎搞的东西。我之前使用<code>product(hsdr_machine_one, hsff_machine_four)</code>成功地比较了两台机器。但现在我想试着一次完成。在</p> <p>输出将是:</p> ^{pr2}$ <p>然后再比较<code>hsdr_machine_two</code>与<code>hsff_machine_four</code>,<code>five</code>,和{<cd6>}。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>展开嵌套列表,然后查看元素的笛卡尔积。在</p> <pre><code>hsdr_flat = sum(hsdr_machines_list, []) hsff_flat = sum(hsff_machines_list, []) for hsdr, hsff in itertools.product(hsdr_flat, hsff_flat): print hsdr, hsff </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python中两个字典的交集
2 回答
python中两个字符串上的异或操作数?
8 回答
Python中两个字符串中的类似句子
5 回答
Python中两个字符串之间的Hamming距离
7 回答
python中两个字符串之间的匹配模式
2 回答
python中两个字符串之间的按位或
1 回答
python中两个字符串之间的数据(字节)切片
7 回答
python中两个字符串之间的模式
2 回答
python中两个字符串作为子字符串的区别
7 回答
Python中两个字符串元组的比较
2 回答
Python中两个字符串列表中的公共字符串
8 回答
python中两个字符串的Anagram测试
3 回答
Python中两个字符串的正则匹配
3 回答
python中两个字符串的笛卡尔乘积
1 回答
Python中两个字符串相似性的比较
4 回答
python中两个字符串语义相似度的求法
5 回答
Python中两个字符置换成固定长度的字符串,每个字符的数目相等
3 回答
Python中两个对数方程之间的插值和平滑数据
4 回答
Python中两个对象之间的And/Or运算符
5 回答
python中两个嵌套字典中相似键的和值
5 回答