小编Ns6*_*s68的帖子

在多个字典中查找常见字母 - python

我正在使用给定的字符串使代码返回字符。我知道使用计数器功能时更容易使用,但我尽量不使用它。

这是我的代码

class Solution:
    def commonChars(self, A):
        dic = {}
        for i in range(len(A)):
            A[i] = list(A[i])
            dic[i] = self.checkLetter(A[i])
        print(dic)
        
    def checkLetter(self, Letter_list) : 
        letter_cnt = {}
        for l in Letter_list:
            if l in letter_cnt : letter_cnt[l] += 1
            else : letter_cnt[l] = 1
        return letter_cnt
Run Code Online (Sandbox Code Playgroud)

我已经用字典制作了一个字母计数器,但我不知道下一步该做什么。你能给我一个提示吗?

# given input_1 : ["bella","label","roller"]
# expected output is e,l,l because it is common in every string in the given list
>>> ["e","l","l"]

# result of my code
>>> {0: {'a': 1, …
Run Code Online (Sandbox Code Playgroud)

python dictionary

2
推荐指数
1
解决办法
111
查看次数

“\”是什么符号

在代码中,每行都有“\”符号,但我不知道它对文件处理意味着什么?

#define GENERATESTRUCT(Name, Column, DataType) \
string a(#Name); \
int index = 0; \
a.append(".h"); \
FILE* file = fopen(a.c_str(), "wt+"); \
fprintf(file, "#pragma once\n"); \
fprintf(file, "#include <string>\n"); \
fprintf(file, "#include <cstdlib>\n"); \
fprintf(file, "using namespace std;\n\n"); \
fprintf(file, "enum E%s{\n", #Name); \
while (index < column.size()) \
{ \
    fprintf(file, "\te%s_%s,\n", #Name, column[index].c_str()); \
    ++index; \
} \
fprintf(file, "};\n\n"); \
fprintf(file, "class %s{\n", #Name); \
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
40
查看次数

标签 统计

c++ ×1

dictionary ×1

python ×1