title: Python: avoiding if condition for this code?
body: <p>for the following code </p>
  
  <pre><code>a =func()
  if a != None:
      b.append(a)
  </code></pre>
  
  <p>a can be assigned to None, is there a way to avoid the if statement and only use one line of code?</p>
  
  <p>original problem is the following</p>
  
  <pre><code>import xml.etree.ElementTree as etree
  
  r = etree.parse(f).getroot()
  b = etree.Element('register',{})
  
  a = r.find('tag_name') # a may get None if did not find it
  if a != None:
      b.append(a)
  </code></pre>
  
  <p>ok, I used all the answers and got this, personally I think it's the most complex python I have ever wrote so far, lol</p>
  
  <pre><code>NS_MAP = {
      'spirit' : 'http://www.spiritconsortium.org/XMLSchema/SPIRIT/1.4',
      'app' : 'http://www.app.com/SPIRIT-app'
      }
  
  mp=etree.Element('MemoryProperty', {'version':'alpha'})
  mpt=etree.ElementTree(mp)
  
  
  def copy_tags(tp, op, p, tn, ns='spirit'):
      c =  p.find('{%s}%s'%(NS_MAP[ns],tn))
      if c is not None:
          (op == '&lt;-') and tp.append(c)
          return c    
  
  for reg in regs:
      te = etree.Element('register',{})
      copy_tags(te,'&lt;-',reg,'name')
      copy_tags(te,'&lt;-',reg,'addressOffset')
      copy_tags(te,'&lt;-',reg,'access')
      (lambda e, t: copy_tags(te,'&lt;-',t,'usageConstraints',ns='app') if t is not None else None)(te, copy_tags(te,'|',reg,'vendorExtensions'))
  
      mp.append(te)
  
  mpt.write('map_gen.xml')
  </code></pre>