Courseiva

EX294 Transform data with filters and plugins Practice Question

You have a list `my_list` containing `[0, 1, 2, '', 'hello']`. You want to extract the first truthy element that exists. Which chain achieves this?

⚠ Common exam trap

It's easy for candidates to think `first` alone returns the first truthy element, but it actually returns the first element regardless of its truthiness, leading to a falsy result like `0` or `''`.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

`my_list | select('truthy') | first | default('')`

`select('truthy')` filters the list to include only elements that evaluate to `true` in Ansible/Jinja2 (non-zero numbers, non-empty strings, etc.), and `first` returns the first such element. The `default('')` provides a fallback if no truthy element exists. This chain correctly extracts `1` from the list `[0, 1, 2, '', 'hello']`.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    `my_list | select('truthy') | first | default('')`

    Why this is correct

    Correct; select truthy, then first, then default.

  • ✗

    `my_list | list | first | default('')`

    Why it's wrong here

    Incorrect; list conversion does not help.

  • ✗

    `my_list | select('string') | first | default('')`

    Why it's wrong here

    Incorrect; select('string') picks only strings, missing 1,2.

  • ✗

    `my_list | first | default('')`

    Why it's wrong here

    Incorrect; `first` returns 0, which is falsy, and default may not trigger.

About these practice questions

This EX294 question is part of Courseiva's 392-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This EX294 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX294 exam.