fix 字符串差异

This commit is contained in:
NY 2025-06-05 16:58:44 +08:00
parent 6d0ed6372e
commit 28568a1792
2 changed files with 8 additions and 8 deletions

Binary file not shown.

View File

@ -53,7 +53,7 @@ def process(input_strings: list) -> list:
matched = True
break
if not matched:
missing_in_1.append(f"{val:.6f} (位置 {idx})")
missing_in_1.append((idx, f"{val:.6f} (位置 {idx})"))
for val, idx in nums1:
matched = False
for v2 in set2:
@ -61,35 +61,35 @@ def process(input_strings: list) -> list:
matched = True
break
if not matched:
missing_in_2.append(f"{val:.6f} (位置 {idx})")
missing_in_2.append((idx, f"{val:.6f} (位置 {idx})"))
else:
set1 = {n[0] for n in nums1}
set2 = {n[0] for n in nums2}
for val, idx in nums2:
if val not in set1:
missing_in_1.append(f"{val:.6f} (位置 {idx})")
missing_in_1.append((idx, f"{val:.6f} (位置 {idx})"))
for val, idx in nums1:
if val not in set2:
missing_in_2.append(f"{val:.6f} (位置 {idx})")
missing_in_2.append((idx, f"{val:.6f} (位置 {idx})"))
except ValueError:
return ["错误:输入包含无法转换为数值的元素"]
else:
set1, set2 = set(elements1), set(elements2)
for i, e in enumerate(elements2, 1):
if e not in set1:
missing_in_1.append(f"{e} (位置 {i})")
missing_in_1.append((i, f"{e} (位置 {i})"))
for i, e in enumerate(elements1, 1):
if e not in set2:
missing_in_2.append(f"{e} (位置 {i})")
missing_in_2.append((i, f"{e} (位置 {i})"))
if missing_in_1:
result.append("字符串1相对于字符串2缺少")
result.extend(sorted(missing_in_1))
result.extend(item[1] for item in sorted(missing_in_1, key=lambda x: x[0]))
else:
result.append("字符串1相对于字符串2没少")
if missing_in_2:
result.append("字符串2相对于字符串1缺少")
result.extend(sorted(missing_in_2))
result.extend(item[1] for item in sorted(missing_in_2, key=lambda x: x[0]))
else:
result.append("字符串2相对于字符串1没少")