New to Python and am having a problem with getting items into individual elements of a list. I am walking through a subdirectory list and want to write each subdirectory to a separate dimension on a list. So my output would be:
[['roll_274_oe_2014-09-26',
['roll_275_oe_2014-10-03'],
['roll_276_oe_2014-10-10'],
['roll_277_oe_2014-10-17']]
but instead it looks like I'm iterating through the directory tree the number of times I have the output:
[['roll_274_oe_2014-09-26',
'roll_275_oe_2014-10-03',
'roll_276_oe_2014-10-10',
'roll_277_oe_2014-10-17'],
[], [], [], []]
my code to do this is at present:
d = 'C:/winPython/WinPython-64bit-3.3.5.5/scripts/portofolio/'
s1 = []
for path, subdirs, files in os.walk(d):
s1.append(subdirs)
print(s1)
I hope someone can give me a hand.
Many thanks