I'm trying to replace all identical elements in a list with a new string, and also trying to move away from using loops for everything.
# My aim is to turn:
list = ["A", "", "", "D"]
# into:
list = ["A", "???", "???", "D"]
# but without using a for-loop
I started off with variations of comprehensions:
# e.g. 1
['' = "???"(i) for i in list]
# e.g. 2
list = [list[i] .replace '???' if ''(i) for i in range(len(lst))]
Then I tried to employ Python's map function as seen here:
list[:] = map(lambda i: "???", list)
# I couldn't work out where to add the '""' to be replaced.
Finally I butchered a third solution:
list[:] = ["???" if ''(i) else i for i in list]
I feel like I'm moving further from a sensible line of attack, I just want a tidy way to complete a simple task.