Python nested list context concatenation

I have a list of lists in python that looks like this:

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

      

I want to create a line like this:

a,b;c,d

      

Thus, lists must be separated by character ;

, and values โ€‹โ€‹of the same list must be separated by character,

So far I've tried ','.join([y for x in test for y in x])

that returns a,b,c,d

. Not quite there, though, as you can see.

+3


source to share


3 answers


";".join([','.join(x) for x in a])

      



+8


source


>>> ';'.join(','.join(x) for x in [['a', 'b'], ['c', 'd']])
'a,b;c,d'

      



+6


source


To do this functionally, you can use a map:

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


print(";".join(map(".".join, l)))
a.b;c.d

      

0


source







All Articles