The function below does too many things at once — it validates, transforms and collects all in one loop.
# dirty
def solve(users):
result = []
for u in users:
if u['age'] >= 18 and '@' in u['email'] and u['name'].strip() != '':
result.append({'name': u['name'].strip(), 'email': u['email'].lower(), 'adult': True})
return resultRefactor `solve(users)` by extracting helper functions so each function does exactly one thing. The output must be identical.
Your extracted version should have at minimum: is_valid(user), format_user(user), and the main solve(users) that composes them.
Sample tests