title: Python - check if a generator is empty or not
body: <p>I am trying to build a function in order to return true if a key already exist in a dict or any subdict that is part of this dict, i found this solution : </p>
  
  <pre><code>def gen_dict_extract(key, var):
      if hasattr(var,'iteritems'):
          for k, v in var.iteritems():
              if k == key:
                  yield v
              if isinstance(v, dict):
                  for result in gen_dict_extract(key, v):
                      yield result
              elif isinstance(v, list):
                  for d in v:
                      for result in gen_dict_extract(key, d):
                          yield result
  </code></pre>
  
  <p>but the problem is the result is a generator how to do in order to get true if the key already  exist and false if doesn't 
  Thanks </p>