from collections import defaultdict
def index_lists(list_of_lists):
"""
Indexes the content of a list of lists for batch processing with synchronous execution.
Args:
list_of_lists: A list where each element is a list of items to index.
Returns:
A dictionary where keys are unique items and values are lists of lists
containing the original lists where the item was found.
"""
index = defaultdict(list) # Use defaultdict for easy appending
for lst in list_of_lists:
for item in lst:
index[item].append(lst) # Add list to the item's index
return dict(index) # Convert back to a regular dict
if __name__ == '__main__':
# Example usage
data = [
[1, 2, 3],
[2, 4, 5],
[1, 5, 6]
]
indexed_data = index_lists(data)
print(indexed_data)
Add your comment