title: Is there anyway to structure data to python list or tuple that is efficient
body: <p>Is there any way to structure a data fetched from database, currently I use append but it become slow specially when data fetched is more than 1k</p>
  <pre><code>courses = []
  for i in departments:
      for course in i.course_set.all():
          course = [course.name]
          info_list = []
          for year in range(1, 5):
              info = [year, (['Regular'], ['Irregular'])]
              info_list.append(info)
  
              count = 0
              for gender in ['male', 'female']:
                  regular = students.filter(year_level=year, status='regular', course=course, gender=gender).count()
                  irregular = students.filter(year_level=year, status='irregular', course=course, gender=gender).count()
  
                  info[1][0].append(regular)
                  info[1][1].append(irregular)
  
              regular = students.filter(year_level=year, status='regular', course=course, gender=gender).count()
              irregular = students.filter(year_level=year,status='irregular', course=course, gender=gender).count()
  
              info[1][0].append(regular)
              info[1][1].append(irregular)
              info[1][2].append(cross)
  
              total = regular + irregular
              count += total
              info.append(count)
  
          program.append(info_list)
  
          male = students.filter(gender='male', course=course).count()
          female = students.filter(gender='female', course=course).count()
          overall = students.filter(gender=None), course=course).count()
  
          program.append([&quot;&quot;, &quot;Total&quot;, &quot;&quot;, male, female, overall, overall])
          courses.append(program)
  </code></pre>
  <p>I'm not sure if it is the append or the query hits multiple times on the database. After I get it I will use it to output the data to pdf tables</p>