os.walk
returns a 3 tuple: root, dirs, files
Documentation here
You could use list comprehensions to achieve the split based on filenames.
filenames = reduce(lambda x,y: x+y, [files for root, dirs, files in os.walk('.')])
files = [name[2:7] for name in filenames]
Here are the explanations: Lambda functions are anonymous functions. You do not return anything. The definition contains expressions which are returned. This is powerful in processing dynamically generated data.
reduce()
a.k.a "worker function" accepts two arguments. The function is called with first two elements of the list, then with the result of these, the third element, and so on. The return value is a single list
There are loads of documentation around this online.