Python function: variable and string
<p>I have following formula to check (Thanks for helping me on <a href="http://stackoverflow.com/questions/40102772/python-applying-function-to-list-of-tems/40102936?noredirect=1#comment67478880_40102936">this</a>!).</p>

<pre><code>queries = ['dog','cat','hamster']

    def get_trends(queries):
        return pd.concat([pytrend.trend({'q': x, 'date': '01/2015 12m'}, return_type='dataframe')
    for x in queries], axis=1)

get_trends(queries)
</code></pre>

<p>This function fires a Google Trends query for each item in the list and puts the returning dataframes next to each other. What I need to do now is to do exactly the same, but have each one static variable (pet) in the query.</p>

<p>For example, a query without the formula would be</p>

<pre><code>return pytrend.trend({'q': 'pet, dog', 'date': '01/2015 12m'}, return_type='dataframe')
</code></pre>

<p>I know I could try</p>

<pre><code>queries = ['pet, dog','pet, cat','pet, hamster']
</code></pre>

<p>But maybe there's a more elegant way?</p>

<p>I tried </p>

<pre><code>static =['pet']
return pytrend.trend({'q': ''' + static + x + ''', 'date': '01/2015 12m'}, return_type='dataframe')
</code></pre>

<p>but wasn't successful with that.</p>

<p>You can do it this way:</p>

<pre><code>In [54]: %paste
static = 'animals'
animals = ['dog','cat','hamster']
queries = ['{}, {}'.format(static, x) for x in animals]
## -- End pasted text --

In [55]: queries
Out[55]: ['animals, dog', 'animals, cat', 'animals, hamster']
</code></pre>

<p>now you can pass <code>queries</code> to your function:</p>

<pre><code>get_trends(queries)
</code></pre>

python string list function