Home > Software engineering >  how can i remove ' from my output in python
how can i remove ' from my output in python

Time:10-04

msg1 = "   Facebook already uses AI to Filter Fake stories from the feeds of users "  
Desired output = [Facebook , already, uses, AI, to, Filter, Fake, stories, from, the, feeds, of, users ]​

My code:

msg1 = "  Facebook already uses AI to Filter Fake stories from the feeds of users"
print(msg1.split())

Actual output = ['Facebook', 'already', 'uses', 'AI', 'to', 'Filter', 'Fake', 'stories', 'from', 'the', 'feeds', 'of', 'users']

I'm just getting started into python. i may be using the wrong function or missing anything to remove ' from the output. How can i achieve this simple goal.

CodePudding user response:

msg1 = "  Facebook already uses AI to Filter Fake stories from the feeds of users"
output = str(msg1.split()).replace("'", "")
print(output)

CodePudding user response:

This should work

msg1 = "   Facebook already uses AI to Filter Fake stories from the feeds of users ".split()
print(*msg1, sep=" ")

You can modify the sep so so that you can have the desired character to be in the spaces between each elements. And the default value for sep would be " ".

  • Related