title: How can a Markdown list be parsed to a dictionary in Python?
body: <p>I have list such as the following:</p>
  
  <pre><code>- launchers
     - say hello
        - command: echo "hello" | festival --tts
        - icon: sayHello.png
     - say world
        - command: echo "world" | festival --tts
        - icon: sayWorld.png
     - wait
        - command: for ((x = 0; x &lt; 10; ++x)); do :; done
        - icon: wait.png
  </code></pre>
  
  <p>I would like to parse it to a dictionary like the following:</p>
  
  <pre><code>{
      "launchers": {
          "say hello": {
              "command": "echo \"hello\" | festival --tts",
              "icon": "sayHello.png"
          }
          "say world": {
              "command": "echo \"world\" | festival --tts",
              "icon": "sayWorld.png"
          }
          "wait": {
              "command": "for ((x = 0; x &lt; 10; ++x)); do :; done",
              "icon": "wait.png"
          }
      }
  }
  </code></pre>
  
  <p>I've started on some very manual code that counts leading spaces (e.g. <code>len(line.rstrip()) - len(line.rstrip().lstrip())</code>), but I'm wondering if there is a more sensible way of approaching this. I am aware that JSON can be imported into Python, but this doesn't suit my purposes. So, how can a Markdown list in a file be parsed to a dictionary in Python? Is there an efficient way of doing this?</p>
  
  <p>Here's some basic code I'm playing with now:</p>
  
  <pre><code>for line in open("configuration.md", 'r'):
      indentation = len(line.rstrip()) - len(line.rstrip().lstrip())
      listItem = line.split('-')[1].strip()
      listItemSplit = listItem.split(':')
      key = listItemSplit[0].strip()
      if len(listItemSplit) == 2:
          value = listItemSplit[1].strip()
      else:
          value = ""
      print(indentation, key, value)
  </code></pre>