简体   繁体   中英

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'), ('/tmp/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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM