-4

I have txt file and I want to import text to list in Python. Txt file(If need I can change it): Hi, Hello, Welcome And I want list like that: ['Hi','Hello','Welcome']

Szymon
  • 3
  • 1
  • 5

2 Answers2

0

You mean:

>>>hmm="Welcome And I want list like that"
>>>my_list=hmm.split()
>>>my_list
['Welcome', 'And', 'I', 'want', 'list', 'like', 'that']
mpruchni
  • 290
  • 5
  • 17
0

Basically:

print open('yourfile.txt').read().split(',')

And if you're not sure about extra spaces or tabs in your source file, you can remove them:

print map(str.strip, open('yourfile.txt').read().split(','))
Organis
  • 7,243
  • 2
  • 12
  • 14