Skip to content Skip to sidebar Skip to footer

Python Function: Variable And String

I have following formula to check (Thanks for helping me on this!). queries = ['dog','cat','hamster'] def get_trends(queries): return pd.concat([pytrend.trend({'q': x,

Solution 1:

You can do it this way:

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']

now you can pass queries to your function:

get_trends(queries)

Post a Comment for "Python Function: Variable And String"