title: Python: split string and get position
body: <p>I want to split a string into pieces and want to get additional the (starting) positions of the splitted pieces of the string.</p>
  
  <p>I can do this with the following code:</p>
  
  <pre><code>str_ = '  d     A7    g7'
  flag_non_space_string_started = False
  positions = []
  for i, letter in enumerate(str_):
      if letter is not ' ':
          if not flag_non_space_string_started:
              positions.append(i)
              flag_non_space_string_started = True
      else:
          flag_non_space_string_started = False
  # this is what I want
  print(str_.split())
  print(positions)
  # prints:
  # ['d', 'A7', 'g7']
  # [2, 8, 14]
  </code></pre>
  
  <p>Is there a shorter (more pythonic) way to get the positions?</p>