Skip to content
Advertisement

Concatenating string to list iteratively

So I’m trying to concatenate a string to a list, but for some reason it only works for the very last values:

JavaScript

Input:

JavaScript

Output:

JavaScript

What i need is:

JavaScript

Advertisement

Answer

For me this looks like task for map, I would do

JavaScript

Output:

JavaScript

Explanation: for every pair of corresponding elements from labels and sents I pack first one into list and then concatenate with latter. This solution assumes len(labels)==len(sents) does hold True.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement