title: Create a dictionary with input in python
body: <p>I'm trying to create a dictionary from user input, with the ability to add nested dictionaries as well.
  The code I have now can create a dictionary, with one level nesting, but I think there's a better way to do this and also make the nesting levels be unlimited, does anyone know how to achieve this?</p>
  <pre><code>def input_to_dict():
      def str_or_list(value):
          # return list if values are separated by comma, else return string
          if &quot;,&quot; in value:
              value = value.split(&quot;,&quot;)
              value = [i.strip() for i in value]
              return value
          else:
              return value.strip()
      
      temp_dict = {}
      while True:
          key = input('Key: ').title()
          if not key:
              break
          value = input('Value: ')
          # if value is key-value pair, nest dict
          if &quot;:&quot; in value:
              value = value.split(&quot;:&quot;)
              value_k = value[0].strip().title()
              value_v = value[1].strip()
              temp_dict[key] = {value_k: str_or_list(value_v)}
              
          else:
              temp_dict[key] = str_or_list(value)
          
      return temp_dict
  </code></pre>