Defining a cell with a vector of Regions?

Hi all,
I’m trying to generalize a CSG definition where some cells are free to move around, and others may appear based on others’ locations. I’m using the Python API to define the cells and regions with a function that takes x position as an argument and returns two lists - one is the list of cells and the other is the list of regions (i.e. region_list.append(-box100 & -box101)). I was hoping to take this list of regions and use the complement of each element to define the region for my air-filled “World” volume. Is there a good way to do this?

Basically, is it possible to convert
region_list = [-box100 & -box101, -box102 & -box103]
into
World = openmc.Cell(fill=Air, region = ~region_list[0] & ~region_list[1])
for an arbitrary (and potentially changing) number of list elements?

@sjcrs In addition to the & operator, you can also explicitly instantiate an instance of Intersection which takes an iterable of regions. Thus, the syntax you want is:

World = openmc.Cell(fill=Air, region=openmc.Intersection(~r for r in regions))

If you prefer a functional programming approach, the following should also work:

from operator import and_
from functools import reduce

World = openmc.Cell(fill=Air, region=reduce(and_, [~r for r in regions]))

Perfect, thank you Paul!