0

I have list which content the following words.

      word_list = ['Here', 'is', 'an', 'example', 'of', 'what', 'I', 'am',
                   'working', 'with', 'But', 'I', 'need', 'to', 'change', 'the format',
                   'to', 'something', 'more', 'useable']

i would like to this format

     word_list = [Here is an example of what I am
                    working with But I need to change the format 
                    to something more useable]

Is it possible to achieve that? How can I concatenate the words in the list?

I tried for this code. but I achieves a list of words instead of a sentence.

  blog_posts=[]
  stop = stopwords.words('english')+[
   '.',
   ',',
   '--',
   '\'s',
    '?',
    ')',
   '(',
   ':',
  '\'',
   '\'re',
  '"',
  '-',
  '}',
  '{',
  u'—',
 'a', 'able', ]
 file=open("resources/ch05-webpages/newspapers/25314/Indexpress111.csv","r+")
 #resources\ch05-webpages\newspapers\midday11.csv
 #t=[i for i in file.read().split() if i not in stop]
 t=    [i.replace("'","").replace("?","").replace(":","").replace("\"","").replace("\'","").strip() 

for i in file.read().split() if i not in stop]
 blog_posts.append((t,))
print blog_posts
alvas
  • 115,346
  • 109
  • 446
  • 738
pramod24
  • 1,096
  • 4
  • 17
  • 38
  • `so give me proper solution` ask nicely – Tim Mar 26 '14 at 09:46
  • 1
    Your expected output is not valid Python syntax. You also forgot to post the code you tried. – Frédéric Hamidi Mar 26 '14 at 09:56
  • @timcastelijns, lolz... okay, let's play nice and answer his question properly =) – alvas Mar 26 '14 at 10:24
  • @alvas before the edit there wasn't even a question mark, i found that pretty rude – Tim Mar 26 '14 at 10:27
  • @timcastelijns, now i see =), yeah. let me edit the question to a nicer tone. – alvas Mar 26 '14 at 10:28
  • 1
    I think someone's also working on the same course... It looks like your code is from [this post](http://stackoverflow.com/questions/22576781/how-to-remove-quotes-after-removing-stopwords-from-nltk) with a bit added from [this answer](http://stackoverflow.com/questions/22576781/how-to-remove-quotes-after-removing-stopwords-from-nltk/22585730#22585730)... Perhaps you and Prashant should point out to the instructor that the course is really very unclear if you're both having to ask the same question? :p – Jon Clements Mar 26 '14 at 10:38

1 Answers1

0

Firstly, your word_list is a list. If you want to output the concatenated words as a string, you can use str.join(list), see Explain Python .join(). I would assume your required output is a string that is printable to console or writable to a file, so you can try:

>>> word_list = ['Here', 'is', 'an', 'example', 'of', 'what', 'I', 'am',
...                    'working', 'with', 'But', 'I', 'need', 'to', 'change', 'the format',
...                    'to', 'something', 'more', 'useable']
>>> 
>>> print " ".join(word_list)
Here is an example of what I am working with But I need to change the format to something more useable

If the previous paragraph seem alien to you, then I suggest you go through some basics in python and then come back to the code snippet above to understand it, try http://www.codecademy.com/tracks/python

Community
  • 1
  • 1
alvas
  • 115,346
  • 109
  • 446
  • 738