Question: I have a text that I'm splitting into a list of sentences, and I want to find the subject of each sentence. For example, if the text is 'Dogs are great. They are so awesome', they have to be splitted into the two sentences 'Dogs are great.' and 'They are so awesome'. Then I use a for loop to find what the subject of each sentence is, whether it is 'cats' or 'dogs'.

```
sentence_list=['Dogs are great', 'They are so awesome']
for sentence in sentence_list:
    if 'Dog' in sentence:
        subject= 'Dog'
    elif 'Cat' in sentence:
        subject='Cat'

```

Because 'They' is used as a replacement for one of these, I want to set the subject for that sentence to the same as the last sentence. So in this example, the subject would be 'Dog' for both sentences.

Answer: 
You already have the last value. If neither the `if` clause nor the `elif` clause are true, then `subject` hasn't been set this iteration. That means it will still hold the same value it held last iteration.

```
sentence_list=['Dogs are great', 'They are so awesome']
for sentence in sentence_list:
    if 'Dog' in sentence:
        subject= 'Dog'
    elif 'Cat' in sentence:
        subject='Cat'
    print(subject)

```

Will result in:

```
Dog
Dog

```
I may suggest you to use `startswith()` string method to check if a sentence starts with "They" or "It" for example, and then perform the substitution with the subject of the previous sentences. It is very simple and will probably fail on complex sentences, but it does the job for your question: 

```
sentence_list=['Dogs are great', 'They are so awesome','Cats are nice', 'They can be dangerous']

for i,sentence in enumerate(sentence_list):
    if sentence.startswith('Dogs'):
        subject= 'Dogs'
    elif sentence.startswith('Cats'):
        subject='Cats'
    if sentence.startswith('They'):
        sentence_list[i] = sentence.replace('They', subject)

print(sentence_list)
# ['Dogs are great', 'Dogs are so awesome', 'Cats are nice', 'Cats can be dangerous']

```