Pregunta

I have two lists separated by space: foo bar and baz ban, embedded in a list: (foo bar, baz ban). I want to join the two list by a comma, maintaining the space separator inside the list inside to get:

foo bar, baz ban

How can I do this?

When I do not specify the separator in join function, all gets joined by a space:

@debug join(foo bar, baz ban);
=> DEBUG: foo bar baz ban

When I specify comma for the separator in the join function, all separator becomes a space:

@debug join(foo bar, baz ban, comma);
=> DEBUG: foo, bar, baz, ban
¿Fue útil?

Solución

join() will append one list to the other ... which means that from two one-dimensional lists, with two elements each, it will always make a one-dimensional list with four elements (as you already noticed).

To combine the two lists into a two-dimensional (nested) list with two elements (each being one of your original lists), you should just do something like this:

@debug (foo bar, baz ban);
=> DEBUG: foo bar, baz ban

DEMO

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top