1. from collections import defaultdict
  2. def index_lists(list_of_lists):
  3. """
  4. Indexes the content of a list of lists for batch processing with synchronous execution.
  5. Args:
  6. list_of_lists: A list where each element is a list of items to index.
  7. Returns:
  8. A dictionary where keys are unique items and values are lists of lists
  9. containing the original lists where the item was found.
  10. """
  11. index = defaultdict(list) # Use defaultdict for easy appending
  12. for lst in list_of_lists:
  13. for item in lst:
  14. index[item].append(lst) # Add list to the item's index
  15. return dict(index) # Convert back to a regular dict
  16. if __name__ == '__main__':
  17. # Example usage
  18. data = [
  19. [1, 2, 3],
  20. [2, 4, 5],
  21. [1, 5, 6]
  22. ]
  23. indexed_data = index_lists(data)
  24. print(indexed_data)

Add your comment