在集合列表中查找重复项的计数
嗨,我必须从数据中检查字符串的重叠和重复,我可以这样做,任何人都可以帮助我找到字符串的副本。我有此数据s = [(100,350,“ a”), (125,145,“ a”),(200,400,“ d”),(0,10,“ a”)]
,我完成了重叠部分,但是请检查ODF字符串,我需要帮助。
def overlap(a, b) -> bool:
a_start, a_end, _ = a
b_start, b_end, _ = b
return a_start < b_end and b_start < a_end
ls = [(100, 350,"a"), (125, 145,"a"), (200, 400, "d"), (0, 10, "a")]
overlaps = set()
for idx_a in range(len(ls)):
for idx_b in range(len(ls)):
if idx_a != idx_b:
if overlap(ls[idx_a], ls[idx_b]):
overlaps.add(ls[idx_a])
overlaps.add(ls[idx_b])
print(f"Number of overlaps: {len(overlaps)}")
Hi i have to check the overlapping and duplicate of string from the data , i could do it can anyone help me to find the duplicate of string .I have this data s = [(100, 350,"a"), (125, 145,"a"), (200, 400, "d"), (0, 10, "a")]
and i done the overlap part but theduplicate check odf string i need help .
def overlap(a, b) -> bool:
a_start, a_end, _ = a
b_start, b_end, _ = b
return a_start < b_end and b_start < a_end
ls = [(100, 350,"a"), (125, 145,"a"), (200, 400, "d"), (0, 10, "a")]
overlaps = set()
for idx_a in range(len(ls)):
for idx_b in range(len(ls)):
if idx_a != idx_b:
if overlap(ls[idx_a], ls[idx_b]):
overlaps.add(ls[idx_a])
overlaps.add(ls[idx_b])
print(f"Number of overlaps: {len(overlaps)}")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您不需要使用设置,以防您只需要重叠数量。
我会这样解决您的问题:
It seems like you don't need to use set in case you need only number of overlaps.
I would solve your problem like this: