w3resource

Python: Concatenate all elements in a list into a string and return it

Python Basic: Exercise-27 with Solution

Write a Python program to concatenate all elements in a list into a string and return it.

Pictorial Presentation:

Concatenate all elements in a list into a string and return it

Sample Solution:-

Python Code:

def concatenate_list_data(list):
    result= ''
    for element in list:
        result += str(element)
    return result

print(concatenate_list_data([1, 5, 12, 2]))

Sample Output:

15122

Flowchart:

Flowchart: Concatenate all elements in a list into a string and return it.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to create a histogram from a given list of integers.
Next: Write a Python program to print out all even numbers from a given numbers list in the same order and stop the printing if any numbers that come after 237 in the sequence.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

List comprehension:

>>> m = [x ** 2 for x in range(5)]
>>> m
[0, 1, 4, 9, 16]