title: Generator object to produce kwargs mapping for function
body: <p>I have a generalised generator function, which maps delimited strings to a which yields a kwargs-type dictionary object from a list of delimited strings.</p>
  
  <p>I'd like to use the kwargs-type dictionaries as arguments in another generator function. However, I get the message</p>
  
  <blockquote>
    <p>edge_generator() argument after ** must be a mapping, not generator</p>
  </blockquote>
  
  <p>Here is my current, broken code:</p>
  
  <pre><code>def line_from_file_generator(file_name):
  
      with open(file_name) as text_file:
          for line in text_file:
              yield line
  
  def map_delimited_lines_to_kwargs(lines, delimiter, kwarg_index_map):
  
      for line in lines:
  
          kwargs = {}
          args = line.strip().split(delimiter)
  
          for kwarg, index in kwarg_index_map.items():
              kwargs[kwarg] = args[index]
  
          yield kwargs
  
  
  def edge_generator(source_node_name, destination_node_name, weights):
  
      for line in lines:
          yield Edge(source_node_name, destination_node_name, weights)
  
  
  lines = line_from_file_generator('mit_map.txt')
  kwarg_index_map = {'source_node_name': 0, 'destination_node_name': 1, 'weights': 2}
  kwarg_collection = map_delimited_lines_to_kwargs(lines, ' ', kwarg_index_map)
  edges = edge_generator(**kwargs_collection)
  </code></pre>
  
  <p>I now understand why this is wrong (a generator is a kind of sequence, not a mapping (dict that can be expanded)).</p>
  
  <p>Can I get around this whilst keeping the abstractions I have created? What would the code be? I've tried changing the last line to the below, but it fails to iterate through the kwargs generator, and all edges are generated with the same arguments.</p>
  
  <p><code>edges = edge_generator(**kwarg_collection.next())</code></p>