python - 比较 2 个列表
问题描述
columns = {('400x400', '15', 'C01', 'ST01', 10, 10, 2.2), ('500x500', '18', 'C02', 'ST01', 20, 10, 2.6),
('400x400', '16', 'C01', 'ST02', 10, 10, 2.3), ('500x500', '19', 'C03', 'ST01', 20, 20, 2.5),
('450x450', '14', 'C01', 'ST03', 10, 10, 2.2), ('400x400', '17', 'C03', 'ST02', 20, 20, 2.4),
('400x400', '55', 'C04', 'ST01', 10, 10, 1.2), ('400x400', '57', 'C04', 'ST02', 10, 10, 1.2),
('450x450', '56', 'C04', 'ST03', 10, 10, 1.5)}
columns_group = {}
label = sorted(columns, key=lambda x: x[2])
for key, group in (groupby(label, key=lambda x: x[2])):
columns_group[key] = list(group)
combinations = combinations(columns_group.values(), 2)
c_1 = list(combinations)
for comp in c_1:
if len(comp[0]) == len(comp[1]):
print("length are same")
print(comp)
for col in comp:
column_story = sorted(col, key=lambda x: x[3])
print("Sorted story", column_story)
for i in range(len(column_story)):
if column_story[i][0] == column_story[i][0]:
print("DDDD", column_story[i][0])
**如何在元组列表中进行迭代**
"
length are same
([('400x400', '16', 'C01', 'ST02', 10, 10, 2.3), ('400x400', '15', 'C01', 'ST01', 10, 10, 2.2), ('450x450', '14', 'C01', 'ST03', 10, 10, 2.2)], [('400x400', '55', 'C04', 'ST01', 10, 10, 1.2), ('450x450', '56', 'C04', 'ST03', 10, 10, 1.5), ('400x400', '57', 'C04', 'ST02', 10, 10, 1.2)])
# Line 1
Sorted story [('400x400', '15', 'C01', 'ST01', 10, 10, 2.2), ('400x400', '16', 'C01', 'ST02', 10, 10, 2.3), ('450x450', '14', 'C01', 'ST03', 10, 10, 2.2)]
DDDD 400x400
DDDD 400x400
DDDD 450x450
# line 2
Sorted story [('400x400', '55', 'C04', 'ST01', 10, 10, 1.2), ('400x400', '57', 'C04', 'ST02', 10, 10, 1.2), ('450x450', '56', 'C04', 'ST03', 10, 10, 1.5)]
DDDD 400x400
DDDD 400x400
DDDD 450x450
**如果匹配返回 True,我想根据索引 0 在存储的故事(注释#第 1 行和第 2 行)中进行比较 **
解决方案
推荐阅读
- java - 显示上升数字的简单时钟
- ios - Is it possible MARK: (#pragma mark) in Localizable.string 文件
- java - 安卓 | 充气按钮不起作用
- angular - 延迟加载而不更改angular5中的url
- python - 在 Pandas 类别频率表中未显示 0 计数
- angular - 排序不工作的角材料设计表
- postgresql - 如何在 DB PostgreSql 中禁用嵌套触发器?
- auth0 - DialogFlow/Actions:允许 Google Assistant 用户通过 Actions 应用在 Google 日历中创建事件
- reactjs - 如何使用 Searchkit 创建 Elasticsearch 总和聚合查询?
- .htaccess - htaccess 将语言路径重定向到新路径