我有一个函数clans(),它接受 8 个参数。如果参数不是,我需要将键和值对添加到字典中None。我的解决方案是:
def clans(self, name: str = None, warFrequency: str = None, location: str = None,
minMembers: int = None, maxMembers: int = None,
minClanPoints: int = None, minClanLevel: int = None,
labels: list[str] = None):
params = {} # <- the dictionary to add to
# very much if-conditions
if name is not None:
params['name'] = name
if warFrequency is not None:
params['warFrequency'] = warFrequency
... # <- other function arguments and if conditions …Run Code Online (Sandbox Code Playgroud) 我需要从那个长字符串中提取“rudolf”和“12”"hello, i know that rudolph=12 but it so small..." :使用scanf,我该怎么做?
该缓冲区可以包含任何格式化字符串,例如ruby=45或bomb=1,但我事先并不知道。
我正在尝试类似的事情,但没有成功
#include <stdio.h>
int main()
{
char sentence[] = "hello, i know that rudolph=12 but it so small...";
char name[32];
int value;
sscanf(sentence, "%[a-z]=%d", name, &value);
printf("%s -> %d\n", name, value);
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)