I want this code to work only for Authors AND Contributors

Here you go, and remember, this assumes that your function was already working (I did not check that it was), and if it was, then just wrap like this:

<?php
        add_action( 'admin_menu', 'wf_cli_remove_admin_menu' );
        function wf_cli_remove_admin_menu() {
            $wf_user    = wp_get_current_user();
            $wf_roles   = array( 'contributor', 'author' );
            if( array_intersect( $wf_roles, $wf_user->roles ) ) :
                remove_menu_page( 'index.php' );
                remove_menu_page( 'separator1' );
                remove_menu_page( 'separator2' );
                remove_menu_page( 'edit-comments.php' );
                remove_menu_page( 'edit.php?post_type=tdb_templates' );
                remove_menu_page( 'tools.php' );
            endif;
        }
    ?>

The answer is quite simple to find… ..probably multiple answers on WPStack and then there’s this: https://developer.wordpress.org/reference/functions/current_user_can/#comment-4083