0

Hi I have a csv with sentences in quotes, I want to leave out any sentence which has no more than three words and copy it to the other csv line by line. All help highly appreciated. Thanks

Input csv:

"9795e7dc9a5b032bdb39ace56c08b0e1","Top     Gear","FC Barcelona","Making code names so people dont know who your talking about","Audi A5","Ice cream","Wentworth Miller","Bob Marley","Megan Fox","FIFA","ShootandGoal","Eminem","Nike","Manchester United","Pilotta"
"650c7b5f671972947ef34de59a8e9dd3","Tioga Downs Casino","Ryan Gosling","Crazy, Stupid, Love.","Jane Eyre","Boycott Nike for Resigning Michael Vick"

 Output csv:
 "9795e7dc9a5b032bdb39ace56c08b0e1","Top     Gear","FC Barcelona","Audi A5","Ice cream","Wentworth Miller","Bob Marley","Megan Fox","FIFA","ShootandGoal","Eminem","Nike","Manchester United","Pilotta"
"650c7b5f671972947ef34de59a8e9dd3","Tioga Downs Casino","Ryan Gosling","Jane Eyre"
yadavabhishek
  • 17
  • 1
  • 4
  • Can you show us what you have so far. – grdvnl May 14 '14 at 02:49
  • You don't need a regex for this. [`String.split()`](https://docs.python.org/2/library/string.html?highlight=string#string.split) will [split a string into words](http://stackoverflow.com/questions/743806/split-string-into-a-list-in-python). – Paul May 14 '14 at 03:10

1 Answers1

0

Something (note, this may have to be edited slightly but you gave NO code in your question to work with) like:

newfile = open(newfilename,"w")  
oldfile = open(oldfilename).readlines()


for line in oldfile:
  items = line.split(",")#gets each quoted thing
  for i in items:
      subitems = i.split() #will return a list of each word inside each quoted thing
      if len(subitems) <= 2:
          newfile.write(i + ",")


newfile.close()
Tommy
  • 12,588
  • 14
  • 59
  • 110