<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filter_jobs(sacct_jobs, failed=True):
 """Filter jobs that have a FAILED etc. status."""

    categories = FAILED_CATEGORIES if failed else NORMAL_CATEGORIES
    filtered_jobs = [job for job in sacct_jobs if job['state'] in categories]
    return filtered_jobs