title: Python inline if statement
body: <p>Could someone help me with the syntax of the following or tell me if it is possible or not? As I am going to modify the <code>if ... else ...</code> condition. I don't want to add duplicated values in the list, but I got a <code>KeyError</code>.</p>
  
  <p>Actually, I am not familiar with this kind of statements: </p>
  
  <pre><code>twins[value] = twins[value] + [box] if value in twins else [box]
  </code></pre>
  
  <p>what does this exactly mean?</p>
  
  <p>Sample code</p>
  
  <pre><code>#dictionary
  twins = dict()                  
  #iterate unitlist
  for unit in unitlist:                                              
      #finding each twin in the unit
      for box in unit:                            
          value = values[box]                               
          if len(value) == 2: 
              twins[value] = twins[value] + [box] if value in twins else [box]
  </code></pre>
  
  <p>I modified the condition </p>
  
  <pre><code>#dictionary
  twins = dict()                  
  #iterate unitlist
  for unit in unitlist:                                              
      #finding each twin in the unit
      for box in unit:                            
          value = values[box]                               
          if len(value) == 2:                            
              if value not in twins:                    
                  twins[value] = twins[value] + [box]
  </code></pre>