Duplicate Word Finder
查找文本中重复的单词,显示频数和位置。
关于此工具
重复单词查找工具是一款能够识别并突出显示任何文本中重复单词的工具,并显示其频率计数和确切位置。检测重复单词对于想要改进写作质量、确保用词多样性、并发现可能导致文章显得生硬或冗余的意外重复的作家、编辑和内容创作者来说很有价值。
只需将文本粘贴或输入到输入框中,该工具就会立即分析并找到所有重复的单词。结果以清晰的表格形式呈现,显示每个重复单词、出现次数以及在文本中出现的位置。这样,您可以轻松审查重复情况,并决定每个词是否有目的,或是否应该用同义词替换以改善文章流畅度和可读性。
该工具特别适合小说家、记者、学术写作者以及任何为出版而润色写作的人使用。无论您是在编辑博客文章、论文还是营销文案,重复单词查找工具都能帮助您识别无意中的词汇模式,并保持专业、引人入胜的文章,以吸引读者的注意力。
常见问题
代码实现
import re
from collections import Counter
def find_duplicates(text: str, case_sensitive: bool = False) -> dict:
"""Find duplicate words and their positions in text."""
processed = text if case_sensitive else text.lower()
words = re.findall(r'\b[a-zA-Z]+\b', processed)
freq = Counter(words)
duplicates = {word: count for word, count in freq.items() if count > 1}
# Find positions (1-based word index)
positions = {word: [] for word in duplicates}
for i, word in enumerate(words, 1):
if word in positions:
positions[word].append(i)
return {
'duplicates': sorted(duplicates.items(), key=lambda x: -x[1]),
'positions': positions,
'total_words': len(words),
'unique_words': len(freq),
}
text = "The cat sat on the mat and the cat was happy"
result = find_duplicates(text, case_sensitive=False)
for word, count in result['duplicates']:
print(f"'{word}' appears {count} times at positions {result['positions'][word]}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.