【发布时间】:2014-04-11 13:55:01
【问题描述】:
如何从字符串列表中找到重复列表? 给出了清理函数
def clean_up(s):
""" (str) -> str
Return a new string based on s in which all letters have been
converted to lowercase and punctuation characters have been stripped
from both ends. Inner punctuation is left untouched.
>>> clean_up('Happy Birthday!!!')
'happy birthday'
>>> clean_up("-> It's on your left-hand side.")
" it's on your left-hand side"
"""
punctuation = """!"',;:.-?)([]<>*#\n\t\r"""
result = s.lower().strip(punctuation)
return result
这是我的复制函数。
def duplicate(text):
""" (list of str) -> list of str
>>> text = ['James Fennimore Cooper\n', 'Peter, Paul, and Mary\n',
'James Gosling\n']
>>> duplicate(text)
['james']
"""
cleaned = ''
non_duplicate = []
unique = []
for word in text:
cleaned += clean_up(word).replace(",", " ") + " "
words = cleaned.split()
for word in words:
if word in unique:
我被困在这里.. 我不能使用字典或任何其他技术来计算文本中每个单词的频率。 请帮忙..
【问题讨论】:
标签: python string list python-3.x duplicates