我正在處理來自HP代碼大戰2012的字母分佈問題。我不斷收到一條錯誤消息,指出標識符中的字符無效。這是什麼意思,如何解決。這裏是包含信息的頁面。 hpcodewars.org/past/cw15/problems/2012ProblemsFinalForPrinting.pdf 這裏是代碼標識符中的字符無效
import string
def text_analyzer(text):
'''The text to be parsed and
the number of occurrences of the letters given back
be. Punctuation marks, and I ignore the EOF
simple. The function is thus very limited.
'''
result = {}
# Processing
for a in string.ascii_lowercase:
result [a] = text.lower(). count (a)
return result
def analysis_result (results):
# I look at the data
keys = analysis.keys()
values \u200b\u200b= list(analysis.values \u200b\u200b())
values.sort (reverse = True)
# I turn to the dictionary and
# Must avoid that letters will be overwritten
w2 = {}
list = []
for key in keys:
item = w2.get (results [key], 0)
if item = = 0 :
w2 [analysis results [key]] = [key]
else :
item.append (key)
w2 [analysis results [key]] = item
# We get the keys
keys = list (w2.keys())
keys.sort (reverse = True)
for key in keys:
list = w2 [key]
liste.sort()
for a in list:
print (a.upper(), "*" * key)
text = """I have a dream that one day this nation will rise up and live out the true
meaning of its creed: "We hold these truths to be self-evident, that all men
are created equal. "I have a dream that my four little children will one day
live in a nation where they will not be Judged by the color of their skin but
by the content of their character.
# # # """
analysis result = text_analyzer (text)
analysis_results (results)
請發佈整個追溯 - 它將包括行號,並可能指向無效字符,這將使這個微不足道的答案。 – abarnert 2013-02-13 00:57:40
另外,你是否真的寫了這段代碼,或者是否複製並粘貼了PDF或HTML文件或其他東西?如果是後者,來源是什麼;也許我們可以告訴你如何正確地複製它。 – abarnert 2013-02-13 01:10:15
@abarnert非常感謝您的幫助,但現在它說出了未解決的字符後續續字符 – user2052898 2013-02-13 04:38:38