File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed
Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change 1111}
1212
1313
14- def get_python (item ):
14+ def get_relevant_skills (item ):
15+ """Get the sum of Python and JavaScript skill"""
1516 skills = item [1 ]["skills" ]
16- if "python" in skills :
17- return skills ["python" ]
18- else :
19- # Return value that is equivalent to having no Python skill
20- return 0
2117
18+ # Return default value that is equivalent to no skill
19+ return skills .get ("python" , 0 ) + skills .get ("js" , 0 )
2220
23- print (sorted (data .items (), key = get_python , reverse = True ))
2421
25- # Doing the same thing with lambda function and conditional expression
22+ print (sorted (data .items (), key = get_relevant_skills , reverse = True ))
23+
24+ # Doing the same thing with lambda function
2625print (
2726 sorted (
2827 data .items (),
29- key = lambda item : item [ 1 ][ "skills" ][ "python" ]
30- if " python" in item [1 ]["skills" ]
31- else 0 ,
28+ key = lambda item : (
29+ item [ 1 ][ "skills" ]. get ( " python", 0 ) + item [1 ]["skills" ]. get ( "js" , 0 )
30+ ) ,
3231 reverse = True ,
3332 )
3433)
You can’t perform that action at this time.
0 commit comments