我正在开发一个函数,我需要在字典中找到具有最多值的键(艺术家名称).有时两个键具有相同数量的值,在这种情况下,我需要返回一个艺术家名称列表.
示例词典:
{'M':[("One",1400,30.0, 20.5,"oil paint","Austria"),("Three",1430,100.0,102.0,"watercolor","France")],
'P':[("Eight",1460, 225.0, 200.0, "fresco","Netherlands")],
'U':[("Nine",1203,182.0, 957.0,"egg tempera","Italy"), ("Twelve",1200,76.2,101.6,"egg tempera","France")]
}
Run Code Online (Sandbox Code Playgroud)
对于这个字典,因为M和U具有最多的值(M具有2且U具有2而P仅具有1),所以该函数应该返回
artists_with_most_work(dictionary1())
['M', 'U']
Run Code Online (Sandbox Code Playgroud)
我如何搜索每个键的值的数量并返回最多的键?我认为使用max()会是一个好主意,但我不认为我在下面的当前尝试中正确使用它.感谢任何能提供帮助的人
码:
def artist_with_most_work(db):
matches = []
for key, record_list in db.items():
for record in record_list:
if item in record:
max(db) = themax
matches.append(themax)
return matches
Run Code Online (Sandbox Code Playgroud) 这段代码几乎完美无缺,但似乎忽略了我的if else语句.该程序的目标是仅转换-100到100之间的温度,但由于某种原因,我的代码仍在转换任何输入的数字.这是令人沮丧的,因为我已经尝试了几种不同的方法,但程序永远不会进入else语句并始终运行if语句,即使我说我输入10000.谢谢任何建议将不胜感激
double converter()
{
float C, F, S;
int input;
printf ("Please enter a temperature in Fahrenheit:");
scanf ("%f", &F);
if (F > -100 || F < 100) {
C = FCR * (F -32);
printf ("%f F ==> %f C ", F, C);
printf ("%f", F);
}
else {
F = pow(C, 3);
printf ("Invalid Fahrenheit temperature.");
}
}
Run Code Online (Sandbox Code Playgroud)