I'm trying to make my code more efficient. Currently, I do have two functions doing basically the same inside a while loop. Only the subject (a and b) is different. These two subjects are taking turns with every loop.

This is my framework so far:

```
#run engine
engine_running = True

#set first subject
a = True
b = False

# while engine is running rotate between a and b
while engine_running == True:
       if (a == True):
             Function_a()
             a = False
             b = True
       elif (b == True):
             Function_b()
             a = True
             b = False
       else:
             print('Error')       

```

This is the framework of both functions. It's noteworthy that each function reads the same set of Data, which has Data for a and b.

```
def Function_a():
       import Data
       import random

       # Get Data and the weights
       List = [Data.a_person1, Data.a_person2, Data.a_person3]
       Weight = [List[0]['attribute'],List[1]['attribute'], List[2]['attribute']

       # Choosing a random person based on its attribute
       Selection = random.choices(List,Weight)
       print(Selection[0]['name'], 'has been chosen')

```

```
def Function_b():
       import Data
       import random

       # Get Data and the weights
       List = [Data.b_person1, Data.b_person2, Data.b_person3]
       Weight = [List[0]['attribute'],List[1]['attribute'], List[2]['attribute']

       # Choosing a random person based on its attribute
       Selection = random.choices(List,Weight)
       print(Selection[0]['name'], 'has been chosen')

```

I'm new to python, so I understand this may look ugly and there is probably a nicer and more efficient way of doing this. Currently, it works for me. But maybe you have some input for me?