You can convert both the texts to sets and take the intersection, like this

```
len(set(text_A) & set(text_B)) / len(text_A)
```

But the problem here is, if there is duplicate text then it will be counted only once. So, you might want to use

```
sum(line_A in text_B for line_A in text_A) / len(text_A)
```

But if the `line_A`

can be anywhere in `line_B`

, then what you have is correct and that can be written succinctly like this

```
sum(any(line_A in line_B for line_B in text_B) for line_A in text_A)/len(text_A)
```