I have a list containing arbitrary objects of uniform type:
items = ['a', 'b', 'c', 'x', 'y', 'z']
I'm scanning through the list and marking the objects by placing them in a container based on some unimportant condition. Let's say it's odd indices:
for i in range(len(items)):
if i % 2:
items[i] = (items[i],)
A second pass will filter the list to unwrap the flagged items and remove everything else:
items = [x[0] for x in items if isinstance(x, tuple)]
This code is fundamentally functional. However, for very large arrays, the flagging is increasing memory usage and naturally taking time.
What is the most efficient container to use for something like this? I'm using tuple because it has the smallest footprint of all the container classes I looked at. Is there a better way to wrap a single reference?