fix 字符串差异
This commit is contained in:
parent
6d0ed6372e
commit
28568a1792
BIN
scripts.db
BIN
scripts.db
Binary file not shown.
@ -53,7 +53,7 @@ def process(input_strings: list) -> list:
|
|||||||
matched = True
|
matched = True
|
||||||
break
|
break
|
||||||
if not matched:
|
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:
|
for val, idx in nums1:
|
||||||
matched = False
|
matched = False
|
||||||
for v2 in set2:
|
for v2 in set2:
|
||||||
@ -61,35 +61,35 @@ def process(input_strings: list) -> list:
|
|||||||
matched = True
|
matched = True
|
||||||
break
|
break
|
||||||
if not matched:
|
if not matched:
|
||||||
missing_in_2.append(f"{val:.6f} (位置 {idx})")
|
missing_in_2.append((idx, f"{val:.6f} (位置 {idx})"))
|
||||||
else:
|
else:
|
||||||
set1 = {n[0] for n in nums1}
|
set1 = {n[0] for n in nums1}
|
||||||
set2 = {n[0] for n in nums2}
|
set2 = {n[0] for n in nums2}
|
||||||
for val, idx in nums2:
|
for val, idx in nums2:
|
||||||
if val not in set1:
|
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:
|
for val, idx in nums1:
|
||||||
if val not in set2:
|
if val not in set2:
|
||||||
missing_in_2.append(f"{val:.6f} (位置 {idx})")
|
missing_in_2.append((idx, f"{val:.6f} (位置 {idx})"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return ["错误:输入包含无法转换为数值的元素"]
|
return ["错误:输入包含无法转换为数值的元素"]
|
||||||
else:
|
else:
|
||||||
set1, set2 = set(elements1), set(elements2)
|
set1, set2 = set(elements1), set(elements2)
|
||||||
for i, e in enumerate(elements2, 1):
|
for i, e in enumerate(elements2, 1):
|
||||||
if e not in set1:
|
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):
|
for i, e in enumerate(elements1, 1):
|
||||||
if e not in set2:
|
if e not in set2:
|
||||||
missing_in_2.append(f"{e} (位置 {i})")
|
missing_in_2.append((i, f"{e} (位置 {i})"))
|
||||||
|
|
||||||
if missing_in_1:
|
if missing_in_1:
|
||||||
result.append("字符串1相对于字符串2缺少:")
|
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:
|
else:
|
||||||
result.append("字符串1相对于字符串2没少")
|
result.append("字符串1相对于字符串2没少")
|
||||||
if missing_in_2:
|
if missing_in_2:
|
||||||
result.append("字符串2相对于字符串1缺少:")
|
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:
|
else:
|
||||||
result.append("字符串2相对于字符串1没少")
|
result.append("字符串2相对于字符串1没少")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user