-1

Let's say I have a list of strings like:

my_list = ["house","table","coffe","door"]

I was wondering if there is a way to add the same word in each string inside the list.

For example, let's say I want to add the word "word" in each string. The result would be :

my_list = ["house word","table word","coffe word","door word"]

Do you have an idea on how to do that ?

Thanks!

Kben59
  • 378
  • 2
  • 10

2 Answers2

1

This simple list comprehension should help you:

my_list = ["house","table","coffe","door"]

my_list = [elem+" word" for elem in my_list]

print(my_list)

Output:

['house word', 'table word', 'coffe word', 'door word']
Sushil
  • 5,440
  • 1
  • 8
  • 26
1

You can try with a list comprehension:

my_list = ["house","table","coffe","door"]
my_list = [x+' word' for x in my_word]

Manual way :-;

new_list = []
for x in my_list:
  new_list.append(x+' word')
my_list = new_list[:]
Wasif
  • 14,755
  • 3
  • 14
  • 34