Compare same filenames with different extensions
If your directory is only containing two types of files, I would do the following way, using splitext function and Counter:

import os
from os.path import splitext
from collections import Counter

def compare_text_docx_pdf(path):
    #List containing all file names + their extension in path directory
    myDir = os.listdir(path)
    #List containing all file names without their extension (see splitext doc)
    l = [splitext(filename)[0] for filename in myDir]
    #Count occurences
    a = dict(Counter(l))
    #Print files name that have same name and different extension
    for k,v in a.items():
        if v &gt; 1:
            print(k)