title: How to print key and values as one from a dictionary excluding None
body: <p>I have coded something very simple such as:</p>
  <pre><code>data = [&quot;39&quot;, &quot;40.5&quot;, &quot;41&quot;, &quot;42&quot;, &quot;42.5&quot;, &quot;43&quot;, &quot;44&quot;, &quot;44.5&quot;, &quot;45&quot;, &quot;45.5&quot;, &quot;46&quot;]
  
  characterCount, i = 0, 0
  for j, item in enumerate(data):
  
      if len(item) + characterCount &gt; 20:
          print('\n'.join(data[i:j]))
          characterCount, i = len(item), j
      else:
          characterCount += len(item)
  
  if characterCount:
      print(&quot;if characterCount&quot;)
      print('\n'.join(data[i:]))
  </code></pre>
  <p>However this works very well when is based on a list however I have created a dict that looks like:</p>
  <pre><code>data = {
      '39': ' - (3)',
      '40.5': ' - (4)',
      '41': None,
      '42': ' - (16)',
      '42.5': None,
      '43': ' - (36)',
      '44': ' - (78)',
      '44.5': None,
      '45': ' - (30)',
      '45.5': ' - (12)',
      '46': None
  }
  </code></pre>
  <p>and when I run the code with the dict, it returns: <code>TypeError: unhashable type: 'slice'</code> in row: <code>print('\n'.join(data[i:j]))</code></p>
  <p>My question is, how can I print the key and values as a one value and if a dict has None as value then we just print the key without the &quot;None&quot; value?</p>