-6

all_folders is nested list of interest as below:

all_folders = [['\\\\1234\\Costing\\Folder1\\', '\\\\4567\\Costing\\Folder1\\', '\\\\8910\\Costing\\Folder1\\', '\\\\1112\\Costing\\Folder1\\', '\\\\1314\\Costing\\Folder1\\', '\\\\1516\\Costing\\Folder1\\'], ['\\\\1234\\Costing\\Folder2\\', '\\\\4567\\Costing\\Folder2\\', '\\\\8910\\Costing\\Folder2\\', '\\\\1112\\Costing\\Folder2\\', '\\\\1314\\Costing\\Folder2\\', '\\\\1516\\Costing\\Folder2\\'], ['\\\\1234\\Costing\\Folder3\\', '\\\\4567\\Costing\\Folder3\\', '\\\\8910\\Costing\\Folder3\\', '\\\\1112\\Costing\\Folder3\\', '\\\\1314\\Costing\\Folder3\\', '\\\\1516\\Costing\\Folder3\\']]

Trying to access 0th, 1st, 2nd... indices from nested list above.

What I am looking for is accessing addresses like this: '\\\\1234\\Costing\\Folder1\\' '\\\\1234\\Costing\\Folder2\\', '\\\\1234\\Costing\\Folder3\\' Then move to the next index in sublists: '\\\\4567\\Costing\\Folder1\\', '\\\\4567\\Costing\\Folder2\\', '\\\\4567\\Costing\\Folder3\\'

for folders in all_folders:
    for folder in folders:
    print(folder)

This doesn't give me what I'm trying to access. I want the output as below:

\\1234\Costing\Folder1\ \\1234\Costing\Folder2\ \\1234\Costing\Folder3\ \\4567\Costing\Folder1\ \\4567\Costing\Folder2\ \\4567\Costing\Folder3\ \\8910\Costing\Folder1\ \\8910\Costing\Folder2\ \\8910\Costing\Folder3\ \\1112\Costing\Folder1\ \\1112\Costing\Folder2\ \\1112\Costing\Folder3\ \\1314\Costing\Folder1\ \\1314\Costing\Folder2\ \\1314\Costing\Folder3\ \\1516\Costing\Folder1\ \\1516\Costing\Folder2\ \\1516\Costing\Folder3\

daredevil
  • 1
  • 1
  • Does this answer your question? [How do I make a flat list out of a list of lists?](https://stackoverflow.com/questions/952914/how-do-i-make-a-flat-list-out-of-a-list-of-lists) – aneroid Mar 08 '23 at 23:16
  • No it doesn't. Please see above expected output. – daredevil Mar 09 '23 at 14:44
  • With the added details of what you're actually expecting, then agreed, that's a different issue. Voted to re-open. Hint: Use [`zip()`](https://docs.python.org/3/library/functions.html#zip) – aneroid Mar 09 '23 at 20:24

1 Answers1

-1

Well, for starters, your input is invalid, as you didn't escape the backslashes that mark the end of strings.

'\\1516\Costing\Folder3\' is invalid. You need to use '\\1516\Costing\Folder3\\' instead.

Fixing that, you get this:

all_folders = [['\\1234\Costing\Folder1\\', '\\4567\Costing\Folder1\\', '\\8910\Costing\Folder1\\', '\\1112\Costing\Folder1\\', '\\1314\Costing\Folder1\\', '\\1516\Costing\Folder1\\'], ['\\1234\Costing\Folder2\\', '\\4567\Costing\Folder2\\', '\\8910\Costing\Folder2\\', '\\1112\Costing\Folder2\\', '\\1314\Costing\Folder2\\', '\\1516\Costing\Folder2\\'], ['\\1234\Costing\Folder3\\', '\\4567\Costing\Folder3\\', '\\8910\Costing\Folder3\\', '\\1112\Costing\Folder3\\', '\\1314\Costing\Folder3\\', '\\1516\Costing\Folder3\\']]

Secondly, you used All_folders. Python variables are case sensitive, so make sure you use all_folders instead.

Once you fix that too, using a nested for loop does work:

for folders in all_folders:
     for folder in folders:
             print(folder)
\1234\Costing\Folder1\
\4567\Costing\Folder1\
\8910\Costing\Folder1\
\1112\Costing\Folder1\
\1314\Costing\Folder1\
\1516\Costing\Folder1\
\1234\Costing\Folder2\
\4567\Costing\Folder2\
\8910\Costing\Folder2\
\1112\Costing\Folder2\
\1314\Costing\Folder2\
\1516\Costing\Folder2\
\1234\Costing\Folder3\
\4567\Costing\Folder3\
\8910\Costing\Folder3\
\1112\Costing\Folder3\
\1314\Costing\Folder3\
\1516\Costing\Folder3\
DoubleFelix
  • 9
  • 1
  • 3