python - Altering characters in strings -


code =   ['#+/084&"', '#3*#%#+', '8%203:', ',1$&', '!-*%', '.#7&33&', '#*#71%', ''] 

how can alter list if ,for example, want change of '#' 'd', list appear such:

code =   ['d+/084&"', 'd3*d%d+', '8%203:', ',1$&', '!-*%', '.d7&33&', 'd*d71%', ''] 

you can map replace operation list:

map(lambda x: str.replace(x, '#', 'd'), code) 

if in python 3 might need:

list(map(lambda x: str.replace(x, '#', 'd'), code)) 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -