'Python - check if 1st element in list of tuples exists in string, if it does add 2nd element from tuple to string

I have string values called cols that have the column name and data type:

cols

_LOAD_DATETIME datetime,
_LOAD_FILENAME string,
_LOAD_FILE_ROW_NUMBER int,
_LOAD_FILE_TIMESTAMP datetime,
ID int 

next I have this list of tuples:

comment_list = [('_LOAD_FILE_TIMESTAMP', 'TEST'), ('ID', 'ID of Account')]

I want to check if the 1st position element in comment_list exists in cols the first word of cols, if it does, add the word 'COMMENT' and the 2nd position element to cols.

so cols should now look like:

cols

_LOAD_DATETIME datetime,
_LOAD_FILENAME string,
_LOAD_FILE_ROW_NUMBER int,
_LOAD_FILE_TIMESTAMP datetime COMMENT 'TEST',
ID int COMMENT 'ID of Account'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source