Effective Testing
Test automation with frontend and backend. Model-based testing solutions.
β
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.
β
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.
π 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.
Click here to claim your Sponsored Listing.