Python, list of strings, rows into columns -


so, problem is, want transpose list rows columns example:

["aaa", "bbb", "ccc"] => ["abc", "abc", "abc"]

can't find efficient way it.

you can simple use of zip , unpacking:

strs = ["aaa", "bbb", "ccc"] print zip(*strs) 

output tuples, though:

[('a', 'b', 'c'), ('a', 'b', 'c'), ('a', 'b', 'c')]


for strings can use:

strs = ["aaa", "bbb", "ccc"] print map(''.join, zip(*strs)) # python 3 use: list(map(''.join, zip(*strs))) # @cesar 

output list of strings:

['abc', 'abc', 'abc']

''.join used map tuples strings.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -