Sorry, here's some better formatting, and hopefully a better explanation:::
import time import os import collections from collections import namedtuple grp_list=[] obj_list=[] nt_object = namedtuple('nt_object', 'name att1 att2') # This for loop is just to populate data into object list for increment in range(1,7): att1="nope" att2="nope" if increment % 2 ==0: att1 ="div by 2" if increment % 3 ==0: att2 ="div by 3" obj_list.append(nt_object("object-"+str(increment),att1,att2)) # obj_list now is 6 items -- # [ nt_object(name='object-1', att1='nope', att2='nope'), # nt_object(name='object-2', att1='div by 2', att2='nope'), # nt_object(name='object-3', att1='nope', att2='div by 3'), # nt_object(name='object-4', att1='div by 2', att2='nope'), # nt_object(name='object-5', att1='nope', att2='nope'), # nt_object(name='object-6', att1='div by 2', att2='div by 3') ] ## because I can't append multiple items, I put them into a list for increment in range(1,7): if (increment % 2 ==0) and (increment %3 == 0): grp_list.append(["group-"+str(increment),obj_list[0],obj_list[1],obj_list[2],obj_list[3], obj_list[4]]) elif increment % 2 ==0: grp_list.append(["group-"+str(increment),obj_list[0],obj_list[2],obj_list[4]]) else: grp_list.append(["group-"+str(increment),obj_list[1],obj_list[3],obj_list[5]]) # grp_list now is 6 items -- # [ ['group-1', nt_object(name='object-2', att1='div by 2', att2='nope'), nt_object(name='object-4', att1='div by 2', att2='nope'), nt_object(name='object-6', att1='div by 2', att2='div by 3')], # ['group-2', nt_object(name='object-1', att1='nope', att2='nope'), nt_object(name='object-3', att1='nope', att2='div by 3'), nt_object(name='object-5', att1='nope', att2='nope')], # ['group-3', nt_object(name='object-2', att1='div by 2', att2='nope'), nt_object(name='object-4', att1='div by 2', att2='nope'), nt_object(name='object-6', att1='div by 2', att2='div by 3')], # ['group-4', nt_object(name='object-1', att1='nope', att2='nope'), nt_object(name='object-3', att1='nope', att2='div by 3'), nt_object(name='object-5', att1='nope', att2='nope')], # ['group-5', nt_object(name='object-2', att1='div by 2', att2='nope'), nt_object(name='object-4', att1='div by 2', att2='nope'), nt_object(name='object-6', att1='div by 2', att2='div by 3')], # ['group-6', nt_object(name='object-1', att1='nope', att2='nope'), nt_object(name='object-2', att1='div by 2', att2='nope'), nt_object(name='object-3', att1='nope', att2='div by 3'), nt_object(name='object-4', att1='div by 2', att2='nope'), nt_object(name='object-5', att1='nope', att2='nope')]] ## trying to figure out how to directly reference that ## group-5 has "object-2", "object-4" and "object-6" ## group-2 has "object-1", "object-3" and "object-5" for z in range(len(grp_list)): a=grp_list[z] counter=0 print(a[0]) for increment in a: if counter >0: print (increment.name) counter +=1 # This works, but I'm first having to extract it to a temp list # I was hoping to be able reference it directly using "grp_list"