Python: How can i find a directory that matches the first 3 characters from a string?
Question: I have a directory with 50+ directories inside which are named `"XXX -
something"`

If I have `X = '123'` How can I find the directory that starts with `'123'`?


Answer: You can try this using
[`os.walk`](https://docs.python.org/2/library/os.html#os.walk)

    
    
    import os
    [i[0] for i in os.walk('/path/to/directory/') if i[0].split("/")[-1].startswith(X)]
    

It will return a `list` in the folder `/path/to/directory/` recursively, if
foldername startswith `X (your varibale)`

**OR**

    
    
    [i for i,j,k in os.walk('/path/to/directory/') if i.split("/")[-1].startswith(X)]
    

