title: how to tell if filter() returns a new list
body: <p>When scraping this <a href="http://www.howtocallabroad.com/afghanistan/" rel="nofollow">Afghanistan page</a>, I got an error saying:</p>
  
  <pre><code>Traceback (most recent call last):                                                                                                                                                                                 
    File "extract_table.py", line 23, in &lt;module&gt;                                                                                                                                                                    
      li = dict(chunks([i.text for i in all_td], 2))                                                                                                                                                                 
  ValueError: dictionary update sequence element #28 has length 1; 2 is required
  </code></pre>
  
  <p>But when scraping <a href="http://www.howtocallabroad.com/argentina/" rel="nofollow">Argentina page</a>, code runs fine.</p>
  
  <p>Is there any way on how to tell that if <code>all_td</code> has returned a new list?  I'd like to know what functions in python to use.</p>
  
  <p>something like this pseudocode:</p>
  
  <pre><code>if all_td is new list,
      execute dict(chunks([i.text for i in all_td], 2))
  else
      execute dict(chunks([i.text for i in areatable.findAll('td')], 2))
  </code></pre>
  
  <p>What I want to accomplish is to run the code to both countries afghanistan and argentina.</p>
  
  <p>This is my code</p>
  
  <pre><code>from bs4 import BeautifulSoup                                                                                                                                                                                       
  import urllib2                                                                                                                                                                                                      
  import re                                                                                                                                                                                                           
  
  url = "http://www.howtocallabroad.com/afghanistan" # argentina works fine
  html_page = urllib2.urlopen(url)
  soup = BeautifulSoup(html_page)
  
  areatable = soup.find('table',{'id':'codes'})
  if areatable is None:
      print "areatable is None"
  else:
      d = {}
  
      def chunks(l, n):
              return [l[i : i + n] for i in range(0, len(l), n)]
  
  
      all_td = areatable.findAll('td')
      all_td = filter(lambda x: x.attrs == {}, all_td)
      print "&gt;&gt;&gt;&gt;&gt; all_td=", all_td
  
      li = dict(chunks([i.text for i in all_td], 2))
      print "&gt;&gt;&gt;&gt;&gt; li=", li
  </code></pre>