For example:
l = ["a", "l", "a", "m", "a", "n", "t"]
In this case I want to change every "a" in the list to "e", like this:
l = ["e", "l", "e", "m", "e", "n", "t"]
I tried indexing and stuff, but it doesn't seem to work.
For example:
l = ["a", "l", "a", "m", "a", "n", "t"]
In this case I want to change every "a" in the list to "e", like this:
l = ["e", "l", "e", "m", "e", "n", "t"]
I tried indexing and stuff, but it doesn't seem to work.
You can do this with a list comprehension.
In [1]: l = ["a", "l", "a", "m", "a", "n", "t"]
In [2]: d = {"a": "e"}
In [3]: l = [d.get(i, i) for i in l]
Output:
Out[4]: ['e', 'l', 'e', 'm', 'e', 'n', 't']