我的代码是:
add_filter( 'oembed_response_data', 'disable_embeds_filter_oembed_response_data_' );
function disable_embeds_filter_oembed_response_data_( $data ) {
unset($data['author_url']);
unset($data['author_name']);
return $data;
}
实际结果:
medals = {'Japan':41, 'Russia':56, 'South Korea':21, 'United States':121, 'Germany':42, 'China':70}
def g(k,d):
return d[k]
ks = medals.keys()
top_three = sorted(ks,key=lambda x : g(x,medals),reverse = True)
但想要得到结果
['United States','China','Russia','Germany','Japan','South Korea']
怎么可能,请帮助任何人。
答案 0 :(得分:0)
medals = {'Japan':41, 'Russia':56, 'South Korea':21, 'United States':121, 'Germany':42, 'China':70}
def g(k,d):
return d[k]
ks = medals.keys()
top_three = sorted(ks,key=lambda x : g(x,medals),reverse = True)[:3]
答案 1 :(得分:0)
只需将三个项目的分隔符添加到排序结果中即可:
top_three = sorted(ks,key=lambda x : g(x,medals),reverse = True)[:3]
答案 2 :(得分:0)
required = list(dict(sorted(medals.items(), key = lambda x: x[1],reverse= True)).keys())[:3]
other_approach =list(map(lambda x: x[0],sorted(medals.items(), key = lambda x: x[1],reverse= True)))[:3]