title: trying to understand generators with sample code
body: <p>I'm trying to understand how generators work by converting "pipe" delimited files to csv files (3 files).</p>
  
  <p>When I run below code, it is only converting and writing 1 csv file (c.csv).</p>
  
  <p>I was expecting that, it will convert &amp; write all three files(a.csv, b.csv &amp; c.csv)</p>
  
  <p>Experts, could you help me understand why its not converting 3 files?</p>
  
  <p>Data in each file(3 files):</p>
  
  <pre><code>country|city
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>from typing import Iterator, Iterable
  
  ret={
    "data": [
      {
        "src": "/Users/home/Desktop/python/a.txt"
      },
       {
        "src": "/Users/home/Desktop/python/b.txt"
      },
      {
        "src": "/Users/home/Desktop/python/c.txt"
      }]}
  
  def extract(files:Iterable[dict])-&gt; Iterator[dict]:
      for file in files:
          ret = file.copy()
          with open(file['src']) as f:    
              ret['data']=f.read()
      yield ret
  
  def transform(files: Iterable[dict]) -&gt; Iterator[dict]:
      for file in files:
  
          df = file_to_df(file["data"])
          ret = file.copy()
          ret['data']=df
          yield ret
  
  def load(files: Iterable[dict]) -&gt; Iterator[dict]:
      for file in files:
          f = open(file['src'].replace(".txt",".csv"),'w')
          f.write(file['data'])
          ret = dict(file)
          ret['dest']=file['src'].replace(".txt",".csv")
          yield ret
  
  # Convert pipe to comma
  
  def file_to_df (file:str, boilerplate_stripped=False):
      df = file.replace("|",",")
      return df
  
  # Transform pipe delimited files to csv
  
  raw_files = extract(ret['data'])   
  transform_files = transform(raw_files)
  load_files = load(transform_files)   
  
  keep_keys = ['src', 'dest']
  ret = {
          "data": [dict({k: v for k, v in x.items() if k in keep_keys}) for x in load_files]
      }
  
  print (ret)
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>{'data': [{'src': '/Users/home/Desktop/python/c.txt', 'dest': '/Users/home/Desktop/python/c.csv'}]}
  </code></pre>
  
  <p>Expected Result:</p>
  
  <pre><code>{'data': [{'src': '/Users/home/Desktop/python/a.txt', 'dest': '/Users/home/Desktop/python/a.csv'},
            {'src': '/Users/home/Desktop/python/b.txt', 'dest': '/Users/home/Desktop/python/b.csv'},
            {'src': '/Users/home/Desktop/python/c.txt', 'dest': '/Users/home/Desktop/python/c.csv'}]}
  </code></pre>