title: Appending a List with instances from another class using a For loop
body: <p>In Python 3, How do I append the first name of instance emp_1 and emp_2 in the class Employee to the self.first list in the class Department using a for loop. Currently I'm appending the list manually for each instance. This would be impractical for many instances.</p>
  <pre><code>  class Employee:
  
    def __init__(self,first, last):
      self.first = first
      self.last = last
    
    def __iter__(self):
     yield from self.first
  
    def __str__(self):
      return f'{self.first} {self.last}'
  
  
  emp_1 = Employee('Corey', 'Smith')
  emp_2 = Employee('Bob', 'Jackson')
  
  
  class Department:
  
    def __init__(self):
        self.first = []
        self.last = []
  
    def __iter__(self):
      yield from self.first
      yield from self.last
  
    def add_firstname(self,fname):
      self.first.append(fname)
  
    def add_lastname(self,lname):
      self.last.append(lname)
  
  
  my_department = Department()
  
  #I would rather use a for loop here
  
  my_department.add_firstname(emp_1.first)
  my_department.add_firstname(emp_2.first)
  
  my_department.add_lastname(emp_1.last)
  my_department.add_lastname(emp_2.last)
  
  for name in my_department.first:
    print(name)
  
  for name in my_department.last:
    print(name)
  </code></pre>