'Way to remove surfaces with the same name?
I am trying to find a way to remove repetitive surfaces. I have a list containing "Scenes" which is just a scene and its name: eg
[(<Surface(1600x800x32 SW)>, 'Level1_surf'), (<Surface(1600x800x32 SW)>, 'Background2_surf'), (<Surface(1600x800x32 SW)>, 'Garden_surf')]
essentially, for some reason even when i call scene_check(self) which does the following:
def scene_check(self):
list_of_all_names = []
for scene in self.all_scenes:
list_of_all_names.append(scene[1])
list_of_unique_names= []
for scene in self.all_scenes:
if scene[1] not in list_of_unique_names:
list_of_unique_names.append(scene[1])
new_list = []
for scene in self.all_scenes:
if scene[1] in list_of_unique_names:
new_list.append(scene)
self.all_scenes = new_list
(this is meant to remove any duplicate surfaces, such as if two have "Level1_surf" it will remove the second one, however, this is not happening, and my list ends up as this over time):
DEBUG: all_scenes: [(<Surface(1600x800x32 SW)>, 'Background2_surf'), (<Surface(1600x800x32 SW)>, 'Garden_surf'), (<Surface(1600x800x32 SW)>, 'Level1_surf'), (<Surface(1600x800x32 SW)>, 'Background2_surf'), (<Surface(1600x800x32 SW)>, 'Garden_surf'), (<Surface(1600x800x32 SW)>, 'Level1_surf'), (<Surface(1600x800x32 SW)>, 'Background2_surf'), (<Surface(1600x800x32 SW)>, 'Garden_surf'), (<Surface(1600x800x32 SW)>, 'Level1_surf')]
can anyone either explain why my method doesn't work or provide the proper way to do this? Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|