Beating the Regional Average

Data with PythonHard+10 XP+10

Beating the Regional Average

A company tracks each sales rep's monthly sales and the region they work in. For a team meeting, one region wants to celebrate the reps who sold more than that region's average.

Task: write standouts(sales, region).

  • sales is a list of dictionaries, each with rep, region and amount.
  • Work out the average amount of the reps in region only. Other regions don't count.
  • Return the names of the reps in region whose amount is more than that average, highest amount first.
  • A rep exactly on the average is not included.
  • If region has no reps, return [].

No two reps in the same region have the same amount.

Examples

sales = [{"rep": "Ana", "region": "North", "amount": 1200}, {"rep": "Ben", "region": "South", "amount": 3100}, {"rep": "Cara", "region": "North", "amount": 1850}, {"rep": "Dev", "region": "North", "amount": 950}, {"rep": "Eli", "region": "North", "amount": 2100}]
region = "North"
returns ['Eli', 'Cara']
sales = [{"rep": "Ana", "region": "North", "amount": 1200}, {"rep": "Ben", "region": "South", "amount": 3100}, {"rep": "Fay", "region": "South", "amount": 400}, {"rep": "Gus", "region": "South", "amount": 500}]
region = "South"
returns ['Ben']

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run