title: How to put some of the values of a list inside a dictionary, using python?
body: <p>I have a list (see LIST) that I want to send to a dictionary.</p>
  <p>But I do not want to send all the data. Just some values (see SOME VALUES/FEATURES) which happen to repeat many times. For example, the word &quot;Model: xxx&quot; appears like 7 times. &quot;xxx&quot; is the name of the model and it will change.</p>
  <p>So far I can only put in the dictionary the last values of the list. How can I put all the values from the list into the dictionary?</p>
  <p>SOME VALUES:</p>
  <p>Labels: xxxx</p>
  <p>Model: xxxx</p>
  <p>Image: xxxx</p>
  <p>Inference: xxxx</p>
  <p>Score: xxxx</p>
  <p>TPU_temp(°C): xxxx</p>
  <p>Time(ms): xxx   ---There are 2 of these, I do not know if it is possible to extract ONLY the second one. But if not, no problem. Extracting both will be fine.--</p>
  <p>THIS IS THE CODE - ATTEMPT 1</p>
  <pre><code>#this is to match tha values/features that I want to extract
  regex = re.compile(r'(\w+)\((.+)\):\s(.*)|(\w+:)\s(.*)')
  match_regex = list(filter(regex.match, output))
  match = [line.rstrip('\n') for line in match_regex]
  
  features_wanted='ModelImageTime(ms)InferenceScoreTPU_temp(°C)'
  
  
  #Removing whitespaces and splitting data into &quot;key:value&quot;
  #Sending the values/features into a dictionary
  dct={i.replace(' ','').split(':')[0]:i.replace(' ','').split(':')[1] for i in match if i.replace(' ','').split(':')[0] in features_wanted}
  print(dct, '\n')
  
  </code></pre>
  <p>THIS IS THE DICTIONARY THAT I GET WITH MY CODE - ATTEMPT 1</p>
  <p>Only the last value of the list appears.</p>
  <p><a href="https://i.stack.imgur.com/qEzsD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qEzsD.png" alt="enter image description here" /></a></p>
  <p>THIS IS THE CODE - ATTEMPT 2</p>
  <pre><code>regex = re.compile(r'(\w+)\((.+)\):\s(.*)|(\w+:)\s(.*)')
  match_regex = list(filter(regex.match, data))
  match = [line.rstrip('\n') for line in match_regex]
  
  dixie=dict(list(enumerate(match)))
  </code></pre>
  <p>THIS IS THE DICTIONARY THAT I GET WITH MY CODE - ATTEMPT 2</p>
  <p>Here I am sending all the list into the dictionary. But I haven't removed whitespaces neither divided data into &quot;key:value&quot;
  <a href="https://i.stack.imgur.com/czL88.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/czL88.png" alt="enter image description here" /></a></p>
  <p>LIST (original list looks like this)</p>
  <p><a href="https://i.stack.imgur.com/vqfaK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vqfaK.png" alt="enter image description here" /></a></p>
  <p>THIS IS THE LIST (so you can test)</p>
  <pre><code>[
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: efficientnet-edgetpu-S_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 23.1&quot;,
      &quot;Time(ms): 5.7&quot;,
      &quot;Inference: corkscrew, bottle screw&quot;,
      &quot;Score: 0.03125 &quot;,
      &quot;TPU_temp(°C): 57.05&quot;,
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: efficientnet-edgetpu-M_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 29.3&quot;,
      &quot;Time(ms): 10.8&quot;,
      &quot;Inference: dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk&quot;,
      &quot;Score: 0.09375 &quot;,
      &quot;TPU_temp(°C): 56.8&quot;,
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: efficientnet-edgetpu-L_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 45.6&quot;,
      &quot;Time(ms): 31.0&quot;,
      &quot;Inference: pick, plectrum, plectron&quot;,
      &quot;Score: 0.09766 &quot;,
      &quot;TPU_temp(°C): 57.55&quot;,
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: inception_v3_299_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 68.8&quot;,
      &quot;Time(ms): 51.3&quot;,
      &quot;Inference: ringlet, ringlet butterfly&quot;,
      &quot;Score: 0.48047 &quot;,
      &quot;TPU_temp(°C): 57.3&quot;,
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: inception_v4_299_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 121.8&quot;,
      &quot;Time(ms): 101.2&quot;,
      &quot;Inference: admiral&quot;,
      &quot;Score: 0.59375 &quot;,
      &quot;TPU_temp(°C): 57.05&quot;,
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: inception_v2_224_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 34.3&quot;,
      &quot;Time(ms): 16.6&quot;,
      &quot;Inference: lycaenid, lycaenid butterfly&quot;,
      &quot;Score: 0.41406 &quot;,
      &quot;TPU_temp(°C): 57.3&quot;,
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: mobilenet_v2_1.0_224_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 14.4&quot;,
      &quot;Time(ms): 3.3&quot;,
      &quot;Inference: leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea&quot;,
      &quot;Score: 0.36328 &quot;,
      &quot;TPU_temp(°C): 57.3&quot;,
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: mobilenet_v1_1.0_224_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 14.5&quot;,
      &quot;Time(ms): 3.0&quot;,
      &quot;Inference: bow tie, bow-tie, bowtie&quot;,
      &quot;Score: 0.33984 &quot;,
      &quot;TPU_temp(°C): 57.3&quot;,
      &quot;labels: imagenet_labels.txt &quot;,
      &quot;Model: inception_v1_224_quant_edgetpu.tflite &quot;,
      &quot;Image: insect.jpg &quot;,
      &quot;Time(ms): 21.2&quot;,
      &quot;Time(ms): 3.6&quot;,
      &quot;Inference: pick, plectrum, plectron&quot;,
      &quot;Score: 0.17578 &quot;,
      &quot;TPU_temp(°C): 57.3&quot;,
  ]
  </code></pre>