Python: Represent directory structure tree as list of lists
I have a list of directories extracted from os.walk
. I removed the files because I don't need them.
.
|____A
|____G
|____H
|____K
|____L
|____B
|____I
|____J
|____C
|____D
|____E
|____F
|____M
So it looks like this:
['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
What I actually need is a real representation of the tree structure in a list like so:
['.', ['A' ['G', 'H' ['K', 'L']], ['B' ['I', 'J']], 'C', 'D', 'E', 'F' ['M']]
ty ;)
python list directory treeview
add a comment |
I have a list of directories extracted from os.walk
. I removed the files because I don't need them.
.
|____A
|____G
|____H
|____K
|____L
|____B
|____I
|____J
|____C
|____D
|____E
|____F
|____M
So it looks like this:
['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
What I actually need is a real representation of the tree structure in a list like so:
['.', ['A' ['G', 'H' ['K', 'L']], ['B' ['I', 'J']], 'C', 'D', 'E', 'F' ['M']]
ty ;)
python list directory treeview
2
'H' ['K', 'L']
,'F' ['M']
is not valid syntax. Do you mean['H', ['K', 'L']]
,['F', ['M']]
?
– Ajax1234
Nov 20 '18 at 15:57
hm i am not sure... i mean to represent the structure shown at the top
– zwusel
Nov 20 '18 at 16:02
add a comment |
I have a list of directories extracted from os.walk
. I removed the files because I don't need them.
.
|____A
|____G
|____H
|____K
|____L
|____B
|____I
|____J
|____C
|____D
|____E
|____F
|____M
So it looks like this:
['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
What I actually need is a real representation of the tree structure in a list like so:
['.', ['A' ['G', 'H' ['K', 'L']], ['B' ['I', 'J']], 'C', 'D', 'E', 'F' ['M']]
ty ;)
python list directory treeview
I have a list of directories extracted from os.walk
. I removed the files because I don't need them.
.
|____A
|____G
|____H
|____K
|____L
|____B
|____I
|____J
|____C
|____D
|____E
|____F
|____M
So it looks like this:
['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
What I actually need is a real representation of the tree structure in a list like so:
['.', ['A' ['G', 'H' ['K', 'L']], ['B' ['I', 'J']], 'C', 'D', 'E', 'F' ['M']]
ty ;)
python list directory treeview
python list directory treeview
edited Nov 20 '18 at 16:05
zwusel
asked Nov 20 '18 at 15:50
zwuselzwusel
568
568
2
'H' ['K', 'L']
,'F' ['M']
is not valid syntax. Do you mean['H', ['K', 'L']]
,['F', ['M']]
?
– Ajax1234
Nov 20 '18 at 15:57
hm i am not sure... i mean to represent the structure shown at the top
– zwusel
Nov 20 '18 at 16:02
add a comment |
2
'H' ['K', 'L']
,'F' ['M']
is not valid syntax. Do you mean['H', ['K', 'L']]
,['F', ['M']]
?
– Ajax1234
Nov 20 '18 at 15:57
hm i am not sure... i mean to represent the structure shown at the top
– zwusel
Nov 20 '18 at 16:02
2
2
'H' ['K', 'L']
, 'F' ['M']
is not valid syntax. Do you mean ['H', ['K', 'L']]
, ['F', ['M']]
?– Ajax1234
Nov 20 '18 at 15:57
'H' ['K', 'L']
, 'F' ['M']
is not valid syntax. Do you mean ['H', ['K', 'L']]
, ['F', ['M']]
?– Ajax1234
Nov 20 '18 at 15:57
hm i am not sure... i mean to represent the structure shown at the top
– zwusel
Nov 20 '18 at 16:02
hm i am not sure... i mean to represent the structure shown at the top
– zwusel
Nov 20 '18 at 16:02
add a comment |
2 Answers
2
active
oldest
votes
You can construct a dictionary from the flattened values, and then use recursion:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start, *(_c if any(not isinstance(i, str) for i in _c) else [_c])]
print(_tree('.'))
Output:
['.', ['A', 'G', ['H', ['K', 'L']]], ['B', ['I', 'J']], 'C', 'D', 'E', ['F', ['M']]]
Edit: Python2 version:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start]+(_c if any(not isinstance(i, str) for i in _c) else [_c])
print(_tree('.'))
ty for the input. Sadly i am working with python 2.7 so i can not use starred expressions :(
– zwusel
Nov 20 '18 at 16:10
@zwusel Please see my recent edit for a Python2-compatible solution.
– Ajax1234
Nov 20 '18 at 16:12
add a comment |
this does not return the datatype you are looking for but a nested dictionary (as this feels more natural to me as a tree structure):
from collections import defaultdict
lst = (['.', ['A', 'B', 'C', 'D', 'E', 'F']],
['A', ['G', 'H']], ['A\G', ],
['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ],
['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ],
['D', ], ['E', ], ['F', ['M']], ['F\M', ])
def rec_dd():
""""recursive default dict"""
return defaultdict(rec_dd)
tree = rec_dd()
for here, dirs in lst:
if not here.startswith('.'):
cur_tree = tree['.']
else:
cur_tree = tree
for key in here.split('\'):
cur_tree = cur_tree[key]
for d in dirs:
cur_tree[d] = rec_dd()
you can pretty print it this way:
import json
print(json.dumps(tree, sort_keys=True, indent=4))
and the result is:
{
".": {
"A": {
"G": {
"K": {},
"L": {}
},
"H": {
"K": {},
"L": {}
}
},
"B": {
"I": {},
"J": {}
},
"C": {},
"D": {},
"E": {},
"F": {
"M": {}
}
}
}
Ty, maybe i will change my datatype of choice to a dict...seems to make more sense ;)
– zwusel
Nov 21 '18 at 7:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396710%2fpython-represent-directory-structure-tree-as-list-of-lists%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can construct a dictionary from the flattened values, and then use recursion:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start, *(_c if any(not isinstance(i, str) for i in _c) else [_c])]
print(_tree('.'))
Output:
['.', ['A', 'G', ['H', ['K', 'L']]], ['B', ['I', 'J']], 'C', 'D', 'E', ['F', ['M']]]
Edit: Python2 version:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start]+(_c if any(not isinstance(i, str) for i in _c) else [_c])
print(_tree('.'))
ty for the input. Sadly i am working with python 2.7 so i can not use starred expressions :(
– zwusel
Nov 20 '18 at 16:10
@zwusel Please see my recent edit for a Python2-compatible solution.
– Ajax1234
Nov 20 '18 at 16:12
add a comment |
You can construct a dictionary from the flattened values, and then use recursion:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start, *(_c if any(not isinstance(i, str) for i in _c) else [_c])]
print(_tree('.'))
Output:
['.', ['A', 'G', ['H', ['K', 'L']]], ['B', ['I', 'J']], 'C', 'D', 'E', ['F', ['M']]]
Edit: Python2 version:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start]+(_c if any(not isinstance(i, str) for i in _c) else [_c])
print(_tree('.'))
ty for the input. Sadly i am working with python 2.7 so i can not use starred expressions :(
– zwusel
Nov 20 '18 at 16:10
@zwusel Please see my recent edit for a Python2-compatible solution.
– Ajax1234
Nov 20 '18 at 16:12
add a comment |
You can construct a dictionary from the flattened values, and then use recursion:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start, *(_c if any(not isinstance(i, str) for i in _c) else [_c])]
print(_tree('.'))
Output:
['.', ['A', 'G', ['H', ['K', 'L']]], ['B', ['I', 'J']], 'C', 'D', 'E', ['F', ['M']]]
Edit: Python2 version:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start]+(_c if any(not isinstance(i, str) for i in _c) else [_c])
print(_tree('.'))
You can construct a dictionary from the flattened values, and then use recursion:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start, *(_c if any(not isinstance(i, str) for i in _c) else [_c])]
print(_tree('.'))
Output:
['.', ['A', 'G', ['H', ['K', 'L']]], ['B', ['I', 'J']], 'C', 'D', 'E', ['F', ['M']]]
Edit: Python2 version:
import re
d = ['.', ['A', 'B', 'C', 'D', 'E', 'F']], ['A', ['G', 'H']], ['A\G', ], ['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ], ['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ], ['D', ], ['E', ], ['F', ['M']], ['F\M', ]
new_d = {re.findall('.$', a)[0]:b for a, b in d}
def _tree(_start):
if not new_d[_start]:
return _start
_c = [_tree(i) for i in new_d[_start]]
return [_start]+(_c if any(not isinstance(i, str) for i in _c) else [_c])
print(_tree('.'))
edited Nov 20 '18 at 16:12
answered Nov 20 '18 at 16:05
Ajax1234Ajax1234
41k42853
41k42853
ty for the input. Sadly i am working with python 2.7 so i can not use starred expressions :(
– zwusel
Nov 20 '18 at 16:10
@zwusel Please see my recent edit for a Python2-compatible solution.
– Ajax1234
Nov 20 '18 at 16:12
add a comment |
ty for the input. Sadly i am working with python 2.7 so i can not use starred expressions :(
– zwusel
Nov 20 '18 at 16:10
@zwusel Please see my recent edit for a Python2-compatible solution.
– Ajax1234
Nov 20 '18 at 16:12
ty for the input. Sadly i am working with python 2.7 so i can not use starred expressions :(
– zwusel
Nov 20 '18 at 16:10
ty for the input. Sadly i am working with python 2.7 so i can not use starred expressions :(
– zwusel
Nov 20 '18 at 16:10
@zwusel Please see my recent edit for a Python2-compatible solution.
– Ajax1234
Nov 20 '18 at 16:12
@zwusel Please see my recent edit for a Python2-compatible solution.
– Ajax1234
Nov 20 '18 at 16:12
add a comment |
this does not return the datatype you are looking for but a nested dictionary (as this feels more natural to me as a tree structure):
from collections import defaultdict
lst = (['.', ['A', 'B', 'C', 'D', 'E', 'F']],
['A', ['G', 'H']], ['A\G', ],
['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ],
['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ],
['D', ], ['E', ], ['F', ['M']], ['F\M', ])
def rec_dd():
""""recursive default dict"""
return defaultdict(rec_dd)
tree = rec_dd()
for here, dirs in lst:
if not here.startswith('.'):
cur_tree = tree['.']
else:
cur_tree = tree
for key in here.split('\'):
cur_tree = cur_tree[key]
for d in dirs:
cur_tree[d] = rec_dd()
you can pretty print it this way:
import json
print(json.dumps(tree, sort_keys=True, indent=4))
and the result is:
{
".": {
"A": {
"G": {
"K": {},
"L": {}
},
"H": {
"K": {},
"L": {}
}
},
"B": {
"I": {},
"J": {}
},
"C": {},
"D": {},
"E": {},
"F": {
"M": {}
}
}
}
Ty, maybe i will change my datatype of choice to a dict...seems to make more sense ;)
– zwusel
Nov 21 '18 at 7:41
add a comment |
this does not return the datatype you are looking for but a nested dictionary (as this feels more natural to me as a tree structure):
from collections import defaultdict
lst = (['.', ['A', 'B', 'C', 'D', 'E', 'F']],
['A', ['G', 'H']], ['A\G', ],
['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ],
['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ],
['D', ], ['E', ], ['F', ['M']], ['F\M', ])
def rec_dd():
""""recursive default dict"""
return defaultdict(rec_dd)
tree = rec_dd()
for here, dirs in lst:
if not here.startswith('.'):
cur_tree = tree['.']
else:
cur_tree = tree
for key in here.split('\'):
cur_tree = cur_tree[key]
for d in dirs:
cur_tree[d] = rec_dd()
you can pretty print it this way:
import json
print(json.dumps(tree, sort_keys=True, indent=4))
and the result is:
{
".": {
"A": {
"G": {
"K": {},
"L": {}
},
"H": {
"K": {},
"L": {}
}
},
"B": {
"I": {},
"J": {}
},
"C": {},
"D": {},
"E": {},
"F": {
"M": {}
}
}
}
Ty, maybe i will change my datatype of choice to a dict...seems to make more sense ;)
– zwusel
Nov 21 '18 at 7:41
add a comment |
this does not return the datatype you are looking for but a nested dictionary (as this feels more natural to me as a tree structure):
from collections import defaultdict
lst = (['.', ['A', 'B', 'C', 'D', 'E', 'F']],
['A', ['G', 'H']], ['A\G', ],
['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ],
['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ],
['D', ], ['E', ], ['F', ['M']], ['F\M', ])
def rec_dd():
""""recursive default dict"""
return defaultdict(rec_dd)
tree = rec_dd()
for here, dirs in lst:
if not here.startswith('.'):
cur_tree = tree['.']
else:
cur_tree = tree
for key in here.split('\'):
cur_tree = cur_tree[key]
for d in dirs:
cur_tree[d] = rec_dd()
you can pretty print it this way:
import json
print(json.dumps(tree, sort_keys=True, indent=4))
and the result is:
{
".": {
"A": {
"G": {
"K": {},
"L": {}
},
"H": {
"K": {},
"L": {}
}
},
"B": {
"I": {},
"J": {}
},
"C": {},
"D": {},
"E": {},
"F": {
"M": {}
}
}
}
this does not return the datatype you are looking for but a nested dictionary (as this feels more natural to me as a tree structure):
from collections import defaultdict
lst = (['.', ['A', 'B', 'C', 'D', 'E', 'F']],
['A', ['G', 'H']], ['A\G', ],
['A\H', ['K', 'L']], ['A\G\K', ], ['A\G\L', ],
['B', ['I', 'J']], ['B\I', ], ['B\J', ], ['C', ],
['D', ], ['E', ], ['F', ['M']], ['F\M', ])
def rec_dd():
""""recursive default dict"""
return defaultdict(rec_dd)
tree = rec_dd()
for here, dirs in lst:
if not here.startswith('.'):
cur_tree = tree['.']
else:
cur_tree = tree
for key in here.split('\'):
cur_tree = cur_tree[key]
for d in dirs:
cur_tree[d] = rec_dd()
you can pretty print it this way:
import json
print(json.dumps(tree, sort_keys=True, indent=4))
and the result is:
{
".": {
"A": {
"G": {
"K": {},
"L": {}
},
"H": {
"K": {},
"L": {}
}
},
"B": {
"I": {},
"J": {}
},
"C": {},
"D": {},
"E": {},
"F": {
"M": {}
}
}
}
edited Nov 20 '18 at 16:22
answered Nov 20 '18 at 16:15
hiro protagonisthiro protagonist
18.4k64060
18.4k64060
Ty, maybe i will change my datatype of choice to a dict...seems to make more sense ;)
– zwusel
Nov 21 '18 at 7:41
add a comment |
Ty, maybe i will change my datatype of choice to a dict...seems to make more sense ;)
– zwusel
Nov 21 '18 at 7:41
Ty, maybe i will change my datatype of choice to a dict...seems to make more sense ;)
– zwusel
Nov 21 '18 at 7:41
Ty, maybe i will change my datatype of choice to a dict...seems to make more sense ;)
– zwusel
Nov 21 '18 at 7:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396710%2fpython-represent-directory-structure-tree-as-list-of-lists%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
'H' ['K', 'L']
,'F' ['M']
is not valid syntax. Do you mean['H', ['K', 'L']]
,['F', ['M']]
?– Ajax1234
Nov 20 '18 at 15:57
hm i am not sure... i mean to represent the structure shown at the top
– zwusel
Nov 20 '18 at 16:02