Question: I have a folder `/image/` that has the following files: 
`1.jpg, 2.jpg, 5.jpg`

And a list:

```
img = [1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg]

```

How do I compare the list and the directory contents to find out that `3.jpg` and `4.jpg` files are missing?

I searched online but the only solutions I found show how to compare list to list or directory to directory.

Answer: 
```
import os
path= r"C:\yourdirectory"  
fileList = os.listdir(path)

img = [...]
missing = [name for name in img if name not in fileList]

```

If order is not important you can use sets instead

```
import os
path= r"C:\yourdirectory"  
fileSet = set(os.listdir(path))

img = [...]
missing = set(img)-fileSet

```
What about this .

Get all file extension first from a file 

```
import os
createlist = []
for r,d,f in os.walk("/images"):
    for files in f:
        if files.endswith(".jpg"):
             createlist.append[files]

```

And then compare both list like.

```
print [(i,j) for i,j in zip(img,createlist) if i!=j]

```