Question: I have a text document and I need to add two @ symbols before the keywords present in an array.

**Sample text and Array:**

```
str ="This is a sample text document which consists of all demographic information of employee here is the value you may need,name: George employee_id:14296blood_group:b positive this is the blood group of the employeeage:32"

arr=['name','employee_id','blood_group','age']

```

**Required Text:**

```
str ="This is a sample text document which consists of all demographic information of employee here is the value you may need, @@name: George @@employee_id:14296 @@blood_group:b positive this is the blood group of the employee @@age:32"

```

Answer: 
Just use the `replace` function

```
str ="This is a sample text document which consists of all demographic information of employee here is the value you may need,name: George employee_id:14296blood_group:b positive this is the blood group of the employeeage:32"
arr = ['name','employee_id','blood_group','age']

for w in arr:
    str = str.replace(w, f'@@{w}')
print(str)

```
You might use `re` module for that task following way

```
import re
txt = "This is a sample text document which consists of all demographic information of employee here is the value you may need,name: George employee_id:14296blood_group:b positive this is the blood group of the employeeage:32"
arr=['name','employee_id','blood_group','age']
newtxt = re.sub('('+'|'.join(arr)+')',r'@@\1',txt)
print(newtxt)

```

Output:

```
This is a sample text document which consists of all demographic information of employee here is the value you may need,@@name: George @@employee_id:14296@@blood_group:b positive this is the blood group of the employee@@age:32

```

Explanation: here I used regular expression to catch words from your list and replace each with @@word. This is single pass, as opposed to X passes when using multiple str.replace (where X is length of `arr`), so should be more efficient for cases where `arr` is long.