Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

processing of list of list

Tags:

python

list

I am working on lists of list

input:

x = [['a','a','a'],['b','b','b'],['c','c','c'],['d','d','d']]

and am looking for an output:

s = ['a_b_c_d','a_b_c_d','a_b_c_d']

Kindly let me know how can I do this using list comprehension.

like image 901
user1369478 Avatar asked Nov 19 '25 02:11

user1369478


1 Answers

>>> x = [['a','a','a'],['b','b','b'],['c','c','c'],['d','d','d']]
>>> map('_'.join, zip(*x))
['a_b_c_d', 'a_b_c_d', 'a_b_c_d']

… although @aix's list comprehension is more list-comprehensible.

like image 170
eumiro Avatar answered Nov 20 '25 18:11

eumiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!