0

So basically I have a list with 4 items.

list = ['My', 'name', 'is', 'mike']

What I want to do is to remove the commas that split the items and make one string. The removed commas should be replaced with space. What I have seen so far is the replace method for string's. I have been wondering if there is something similar for lists.

Blinxen
  • 807
  • 2
  • 13
  • 26

2 Answers2

4

Use

>>> ' '.join(list)
'My name is mike'
akash karothiya
  • 5,736
  • 1
  • 19
  • 29
0

You could join the items of your list using a whitespace ' ' as the separator

list = ['My', 'name', 'is', 'mike']
oneString = ' '.join(list)

This question has already been asked and answered in more detail here Concatenate item in list to strings .

JulianKarlBauer
  • 267
  • 2
  • 13