iterate over list of keywords, surround them with a quote and concat them with or
def keywords_search_string(keywords): query_str = '' for keyword in keywords: query_str += '"' + keyword + '" OR ' return query_str[:-4] keywords_search_string(['machine learning', 'data science'])