-
SortingAlgorithmsLogic
Description Create a function wich takes in a list of tuples which contain a name of a worker and their annualy salary and return a tuple with the five workers with the highest salary in descending order. Unluckily for you, the salary of some workers is unknown and hence represented as "-". Those workers shouldn't be in your final tuple.
Examples:
Input: [("max", "20000"), ("jason", "40000"), ("christian", "70000"), ("carl", "50000")] => Output: ("christian", "carl", "jason", "max")
Input: [("worker0", "-"), ("stephy", "100000"), ("king", "10000")] => Output: ("stephy", "king")
Input: [("ironman", "20000"), ("batman", "15000"), ("kenobi", "150000"), ("mr. x", "40000"), ("spiderman", "75000"), ("ramsay", "115000")] => Output: ("kenobi", "ramsay", "spiderman", "mr. x", "ironman")
Happy coding :-)
Code def sort_by_salary(workers): filtered = list(filter(lambda x: x[1] != "-", workers)) if not filtered: return tuple() new = list(sorted(filtered, key=lambda x: int(x[1])))[::-1] return tuple(i[0] for i in new)[:5]
Output:
-
- All
- {{group.name}} ({{group.count}})
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report