from typing import Iterator
import re


def _extract_problems(urls_with_problems_generator: Iterator, regex: dict) -> list:
    """
    Extract problems from a Iterator of a Google Pagespeed Result
    """
    temp_list = []
    for el in urls_with_problems_generator:
        for reg in regex['watch']:
            if re.search(reg, el["url"]):
                temp_list.append(el)

    if len(regex['ignore']) == 0:
        final_list = temp_list
    else:
        final_list = []
        for el in temp_list:
            for reg in regex['ignore']:
                if not re.search(reg, el["url"]):
                    final_list.append(el)

    return final_list