-4
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.

  • 2
    Since you're new to Python, _why_ do you (think) you need `[Facebook , already, uses,...` as your desired output, instead of `['Facebook', 'already', 'uses'...`? See the first answer of the linked duplicate for an explanation. You realize that the "desired output" version is _not_ a list? – msanford Oct 03 '21 at 15:06

2 Answers2

1
msg1 = "  Facebook already uses AI to Filter Fake stories from the feeds of users"
output = str(msg1.split()).replace("'", "")
print(output)
Eat Ing
  • 312
  • 1
  • 3
  • 7
1

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 " ".

Agent47
  • 91
  • 7