【发布时间】:2017-03-20 22:35:57
【问题描述】:
s = str(input("Please enter your line of text: ").lower())
only_vowels = re.sub(r"[^aeiou]", "", s)
c = (Counter(list(only_vowels)))
print(c)
if len(c) >= 1:
most = c.most_common()[-1]
result = (most[0])
i = -2
if len(c)>=2:
while (c.most_common()[i][1]) == most[1]:
result = ", ".join((result, c.most_common()[i][0]))
i = i-1
print("The least common vowel(s) in the inserted sentence is/are", (result),"and it/they appear(s)",most[1],"times.")
else:
print("You have not inserted any vowels into this sentence.")
这段代码'while (c.most_common()[i][1]) == most[1]:'
有什么想法吗?
【问题讨论】:
-
c是Counter,对吗? -
如果不了解
c和most变量定义的更多上下文,以及在此 sn-p 之前如何使用它们等,将很难理解这个问题! -
请查看原始问题。我意识到问题是我的计数器功能出现故障。任何想法现在如何解决这个问题(原始 Q 编辑)
-
@LewisFirmin
c是一个Counter对象,并且正在打印。c.most_common()将返回键和值对的列表,然后您可以将其打印出来。 -
谢谢。我很感激。现在已经更改了一些代码并编辑了问题......再次。我现在已经包含了整个编码。如果你有时间,请看一下。
标签: python list loops indexing while-loop