Exclude parent categories from recent posts list

I was able to find a function that worked found here.

First, I added the below code to my functions.php, which excludes the parent categories I do not want:

function custom_get_the_category_list() {
    $categories = get_the_category();
    $exclude1 = get_cat_ID( 'Parent1' );
    $exclude2 = get_cat_ID( 'Parent2' );
    $categories_list="";

    foreach ( $categories as $category ) {
        if ( $category->category_parent == $exclude1
                || $category->cat_ID == $exclude1 || $category->category_parent == $exclude2
                || $category->cat_ID == $exclude2  ) {
            continue;
        }
        $categories_list .=
            '<li><a href="' . get_category_link( $category->cat_ID ) . '">' .
            $category->name .
            '</a></li>';
    }

    return '<ul class="post-categories">' . $categories_list . '</ul>';
}

And then in my loop, instead of using get_the_category_list($post->ID), I used the new function custom_get_the_category_list().

It certainly works, but if anyone finds a simpler solution please post.