-1

I want to delete the same word score from the all elements in list:

scorelist = ['100score', '200score', '300score'] 

scorelist = ['100', '200', '300']
benvc
  • 14,448
  • 4
  • 33
  • 54
Hwan Lee
  • 1
  • 1

2 Answers2

1

According to your comments, you're using Python. How about .replace()?

scorelist = ['100score', '200score', '300score']
newlist = []
for score in scorelist:
  newlist.append(score.replace('score',''))

print(newlist)

Try it here!

In python, strings are immutable - that means they can't be changed. Just doing score.replace('score', '') isn't enough - this function returns a string that we can then capture and use.

Good luck!

Nick Reed
  • 4,989
  • 4
  • 17
  • 37
0

In PHP

function test_alter(&$item1, $key, $prefix)
{

    //  replace string
    $item1= str_replace($prefix, "", $item1);

}

array_walk($scorelist, 'test_alter', 'score');
Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
Raghavan
  • 637
  • 3
  • 12