Because selectedFiles is a tuple, and the logic of processing each item inside it is same. you can iterate it with a for loop.
lines = [os.path.basename(str(os.path.splitext(filename)[0])) for filename in selectedFiles]
#extend lines' length to 5 and fill the space with None
lines = lines + [None] * (5-len(lines))
legend(lines,loc='upper left')