How to concatenate items from a list in python?

1

Let's say I have the result of a list:

['_', '_', '_', '_', '_', '_', '_']

How can I turn it into this?:

['_ _ _ _ _ _ _']

Or even in a variable with the value above

    
asked by anonymous 26.08.2018 / 00:08

2 answers

5

You can use join and then transform its return into an array of a single element.

separator = ' '
array = ['_', '_', '_', '_', '_', '_', '_']
result = [separator.join(array)]
print(result)

The print will be:

['_ _ _ _ _ _ _']
    
26.08.2018 / 00:27
0

You can also use this to get fewer rows.

array = ['_', '_', '_', '_']
result = [' '.join(array)]
print(result)

Result:

['_ _ _ _']
    
29.08.2018 / 17:47