开发者

Problem with the depth of nested elements inside list/tuple

Typing first time here, before i found many helpful tips in stackoverflow, right now i have black hole in my brain and can't figure out how to solve this:

i got:

    dirlist = ['dir1', 'dir2', 'dir3', 'dir4']
    print [('a','b','c'),('x','y','z'),[('/tmp/9/', 'X', e) for e in dirlist ] ]

ant it outputs:

[('a', 'b', 'c'),('x', 'y', 'z'), [('/tmp/9/', 'X', 'dir1'), ('/tmp/9/', 'X', 'dir2'), ('/tmp/9/', 'X', 'dir3'), ('/tm开发者_Python百科p/9/', 'X', 'dir4')]]

and i want:

[('a', 'b', 'c'),('x', 'y', 'z'), ('/tmp/9/', 'X', 'dir1'), ('/tmp/9/', 'X', 'dir2'), ('/tmp/9/', 'X', 'dir3'), ('/tmp/9/', 'X', 'dir4')]

... and the real problem is that i need to do it in one line, in the print statement. Thank you for any suggestions, help needed.


print [('a', 'b', 'c'), ('x', 'y', 'z')] + [('/tmp/9/', 'X', e) for e in dirlist]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜