Say I have a list of strings:
myList = ['apple','banana','orange']
and another string saved into a single variable:
myVariable = 'fudge'
I want to add the suffix _df2
to every element in myList
, and also to myVariable
. Therefore, I want my result to look like this:
>> myList
['apple_df2', 'banana_df2', 'orange_df2']
>> myVariable
'fudge_df2'
Currently I am achieving this with the following code:
myList = [fruit + '_df2' for fruit in myList]
myVariable = myVariable + '_df2'
I am wondering, however, since I am adding the same suffix both times, is there a way to sum these two steps up into one?