title: python: construct listed dictionaries according to a conditional for listed tuples
body: <h1>This list of tuples:</h1>
  
  <pre><code>items = [('Value1','Value2','Value3'),('Value4','Value5','Value6'),('Value7','Value8','Value9')]
  </code></pre>
  
  <p>and I have made a "for" loop to make them listed dictionaries:</p>
  
  <pre><code>final_list = []
  
  for string1, string2, string3 in items:
  
      item_data = ({'key1': string1, 'key2': string2, 'key3': string3})
      final_list.append(item_data)
  
  print final_list
  </code></pre>
  
  <h2>and result is this:</h2>
  
  <pre><code>[{'key1': Value1, 'key2': Value2, 'key3': Value3},{'key1': Value4, 'key2': Value5, 'key3': Value6}...]
  </code></pre>
  
  <p>What I am trying to achieve is insert another key-value pair according to a conditional for the key1,value1(string1) pair.</p>
  
  <p>I placed this conditional inside the for loop above:</p>
  
  <pre><code>if 'Value1' or 'Value4' in string1:
      string4 = 'somevalue1'
  elif 'Value7' or 'Value8' in string1:
      string4 = 'somevalue2'
  else:
      string4 = ''
  </code></pre>
  
  <p>then construsted dictionary as below:</p>
  
  <pre><code>item_data = ({'key1': string1, 'key2': string2, 'key3': string3, 'key4': string4})
  </code></pre>
  
  <p>but I didn't get what I expected and instead it got this:</p>
  
  <pre><code>[{'key1': Value1, 'key2': Value2, 'key3': Value3, 'key4': 'somevalue1'},{'key1': Value4, 'key2': Value5, 'key3': Value6, 'key4': 'somevalue1'}...]
  </code></pre>
  
  <p>I was expecting key4's value to be filled according to the value of key1(string1) and with the above statements but doesn't check the next item. It persists with 'somevalue1'.</p>