0

I would like to update an element from a list.

This is my kind of list:

list= ["toto", "stack" , "element_to_update", "overflow"]

I want to update this list when "toto" and "stack" found as element[0] and element[1] to have my list updated (and concatenate with existing element[2])

The list that I want at the end:

list=["toto", "stack", "element_to_update_is_updated", "overflow"]

What is the best way to do that?

Thanks in advance for your help.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
Maxime.D
  • 19
  • 1

1 Answers1

2

Why not:

l = ["toto", "stack", "element_to_update", "overflow"]
if l[:2] == ['toto','stack']:
    l[2] += '_is_updated'

And now:

print(l)

Is:

['toto', 'stack', 'element_to_update_is_updated', 'overflow']
Gary van der Merwe
  • 9,134
  • 3
  • 49
  • 80
U13-Forward
  • 69,221
  • 14
  • 89
  • 114