title: Counting the number of spaces between words in a file using python?
body: <p>I'm really close. I read through "<a href="https://stackoverflow.com/questions/8864795/number-of-space-between-each-word">number of space between each word</a>" and it does provide this line: </p>
  
  <pre><code>counts = [(len(list(cpart))) for c,cpart in groupby(s) if c == ' ']
  </code></pre>
  
  <p>but I really don't understand it... I understand, or am assuming, C is the delimiter, S is what you're grouping by, and you're putting the resulting list?(new to python, array?) into counts (S is referent to a previously instantiated variable)</p>
  
  <h1>How would I determine something like this?</h1>
  
  <pre><code>                                                  AMOUNT       DATE       
     NAME          ACCOUNT#         DISCOUNT         DUE         DUE
  </code></pre>
  
  <p>I am creating a program that allows me to look at a randomly created COBOL output file headers and use it to create the PIC(X)'s associated.</p>
  
  <h2>Example solution output would be:</h2>
  
  <ol>
  <li>PIC X(30) VALUE SPACES.</li>
  <li>PIC X(6) VALUE "AMOUNT".</li>
  <li>PIC X(8) VALUE SPACES.</li>
  <li>PIC X(4) VALUE "DATE". </li>
  </ol>
  
  <p>the important parts are the numbers. I can determine lengths of strings obviously, but the spaces i'm not sure how...</p>
  
  <p>Here is what I have so far to show i'm working lol: </p>
  
  <pre><code>from itertools import groupby
  from test.test_iterlen import len
  from macpath import split
  from lib2to3.fixer_util import String
  
  file = open("C:\\Users\\Joshua\\Desktop\\Practice\\cobol.cbl", 'r+')
  
  line1 = file.readline()
  split = line1.split()
  print (split)
  print ()
  
  counts = [(len(list(cpart))) for c,cpart in groupby(split) if c == ' ']
  
  print (counts)
  
  
  index = 0
  while index != split.__len__():
      if split[index].strip() != None:
          print ("PICX(" + ") VALUE " + "\"" + split[index] + "\".")
      elif counts[index] == None:
          print ("PICX(" + ") VALUE " + "\"" + split[index] + "\".") 
      index+=1
  </code></pre>