It's not "called twice". It's just how you write a list comprehension. We can "unroll" this list comprehension into a for loop to make it easier to understand:
lst = []
for f in listdir(mypath):
if isfile(join(mypath, f)):
lst.append(f)
Explanation:
[f for f in listdir(mypath) if isfile(join(mypath, f))]
^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
| | Condition to satisfy
| What to iterate over
What to append to output list
The general rule of a list comprehension if that you are iterating over a source list (or some iterable), somehow modifying each element in that source or ensuring it satisfies some condition before appending it to your new output list.
Another example where you want to remove all non-positive numbers from a source list, and double all the positives:
src = [-1, -2, 0, 1, 2]
out = [i*2 for i in src if i > 0]
print(out) # [2, 4]