-1

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

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

scorelist = ['100', '200', '300']
benvc
  • 13,540
  • 3
  • 27
  • 50
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
  • 5,007
  • 4
  • 15
  • 36
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,793
  • 7
  • 34
  • 44
Raghavan
  • 647
  • 3
  • 12