Effective Testing

Effective Testing

Share

Test automation with frontend and backend. Model-based testing solutions.

27/12/2025

βœ… Solution β€” Python Intermediate Task (Part 2)

Here’s a clean, Pythonic solution using filtering and lambda expressions:

def above_average(numbers):
avg = sum(numbers) / len(numbers)
return list(filter(lambda x: x > avg, numbers))

numbers = [3, 10, 7, 14, 1, 9, 20]
print(above_average(numbers))

πŸ”Ž Why this works

Average is calculated once

filter() expresses intent clearly

lambda keeps logic inline

πŸ’‘ Alternative solutions using list comprehensions are equally valid.

27/12/2025

βœ… Solution β€” Python Intermediate Task (Part 1)

Here’s a more advanced and functional-style solution using dictionary comprehension:

def count_words(words):
return {word: words.count(word) for word in set(words)}

words = ["apple", "banana", "apple", "orange", "banana", "apple"]
print(count_words(words))

πŸ”Ž Why this works

set(words) removes duplicates

words.count() maps each word to its frequency

Dictionary comprehension keeps the solution concise

⚠️ Note: This is elegant, but not optimal for very large lists β€” a good interview discussion point.

27/12/2025

🐍 Python Intermediate Task (Part 2)

This task focuses on mapping, filtering, and numerical logic.

πŸ” Task

You are given a list of numbers.

Your task is to:

Calculate the average of the list

Return a new list containing only numbers greater than the average

Assume the list is not empty.

πŸ“₯ Example Input
numbers = [3, 10, 7, 14, 1, 9, 20]

πŸ“€ Expected Output
[10, 14, 20]

🧠 Challenge

Write a function that:

Uses functional or declarative style

Minimizes temporary variables

Is readable and efficient

πŸ”₯ Bonus: Solve it in a single expression.

Want your business to be the top-listed Furniture Store in London?
Click here to claim your Sponsored Listing.

Address

London