如何编写一个函数,该函数将返回一个列表,该列表在单词中添加每个字符的reocurrnce

时间:2016-03-10 23:18:44

标签: python

我想知道如何至少开始这个。它在python中。

#include "stdafx.h"
#include <iostream>

int main()
{
    std::cout << " I have a qustion for you Devante. Here it is . . . if you add the word two to the number 2, what do you get ?";
    int x = 4;
    std::cin >> x;
    std::cout << "Correct, the correct answer is " << x << std::endl;
    return 0;
}

int main()
{   
    std::cout << " Since you got the answer right this time, lets see if you can subtract. What is 6 - 6 ? ";
    int x = 0;
    std::cin >> x;
    std::cout << "Correct, the answer is " << x << std::endl;
    return 0;
}

1 个答案:

答案 0 :(得分:0)

有些事情应该有效:

def count_chars(str):
    letters = dict()
    for c in iter(str):
        letters.setdefault(c, 0)
        letters[c] += 1

    print(letters.items())