I'm going to explain what I want as simple as possible (brainfarts over here atm),
You probably know the game mikado, where you release a bunch of sticks on the table and you have to pick 'm up without touching any other. Well, my brainfart is about the game start: I want to know which sticks are parallel to each other.
So the start is:
n sticks with a direction
the desired result is:
dir1 = [stick1, stick33, stick42, stick2]
dir2 = [stick3, stick55]
dir3 = ...
etc
I'm using some program API so putting a example here would clutter my issue big time. Perhaps an easier example showcase the same which fails as the output should be [dir1, dir1, dir1] [dir2] [dir3].
I think it has something to do with the fact that lists are mutable and therefor the itteration grows?
You probably know the game mikado, where you release a bunch of sticks on the table and you have to pick 'm up without touching any other. Well, my brainfart is about the game start: I want to know which sticks are parallel to each other.
So the start is:
n sticks with a direction
the desired result is:
dir1 = [stick1, stick33, stick42, stick2]
dir2 = [stick3, stick55]
dir3 = ...
etc
I'm using some program API so putting a example here would clutter my issue big time. Perhaps an easier example showcase the same which fails as the output should be [dir1, dir1, dir1] [dir2] [dir3].
I think it has something to do with the fact that lists are mutable and therefor the itteration grows?
mikado = ["dir1", "dir1", "dir2", "dir1", "dir3"] count=0 # master_list = [] for stick in mikado: if count == 0: master_list.append([stick]) count += 1 for index, e in enumerate(master_list): if stick == e[0]: # parallel check master_list[index].append(stick) else: master_list.append([stick]) print master_list # [['dir1', 'dir1', 'dir1'], ['dir2', 'dir2'], ['dir1', 'dir1'], ['dir3', 'dir3'], ['dir3', 'dir3'], ['dir3', 'dir3']]