I want to delete the same word score
from the all elements in list:
scorelist = ['100score', '200score', '300score']
scorelist = ['100', '200', '300']
I want to delete the same word score
from the all elements in list:
scorelist = ['100score', '200score', '300score']
scorelist = ['100', '200', '300']
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)
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!
In PHP
function test_alter(&$item1, $key, $prefix)
{
// replace string
$item1= str_replace($prefix, "", $item1);
}
array_walk($scorelist, 'test_alter', 'score');