我如何将水平列表列入垂直列表
我将如何做到这一点,以便我的元音计数器返回垂直列表,而不是水平列表。每次我使用\ n时,它只是给我一个错误,我不知道自己做错了什么,我是初学者编码员,仍然有问题解决这个问题。我尝试寻找答案,但没有找到任何答案。有人可以帮忙吗?因此,与其看起来像这样{'a':1,'e':1,'i':2,'o':1,'u':1}。
我如何使它看起来像这样垂直
'a': 1
'e': 1
'i': 2
'o': 1
'u': 1
def count_vowels(string, vowels):
string = string.casefold()
count = {}.fromkeys(vowels, 0)
# To count the vowels
for character in string:
if character in count:
count[character] += 1
return count
vowels = ("a", "e", "i", "o", "u")
string = "Counting all the strings"
print(count_vowels(string, vowels))
How would I make it so that my vowel counter returns a vertical list instead of a horizontal list. Every time I use \n it just gives me an error I have no clue what I am doing wrong, I am a beginner coder and still have problems solving this. I have tried looking for an answer and I haven't found any. Could anybody help? So instead of looking like this {'a': 1, 'e': 1, 'i': 2, 'o': 1, 'u': 1}.
How do I make it look vertical like this
'a': 1
'e': 1
'i': 2
'o': 1
'u': 1
def count_vowels(string, vowels):
string = string.casefold()
count = {}.fromkeys(vowels, 0)
# To count the vowels
for character in string:
if character in count:
count[character] += 1
return count
vowels = ("a", "e", "i", "o", "u")
string = "Counting all the strings"
print(count_vowels(string, vowels))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想要Python的默认格式以外的其他内容,那么您必须自己做:
If you want something other than Python's default formatting, then you have to do it yourself:
通过将字典施放到字符串和切片(或剥离)中,支架应起作用:
By casting the dictionary to string and slice (or strip) the brackets should work: