I was looking for an algorithm to replace some content inside a list with another. For example, changing all "0" to "X".
I found this piece of code that works:
list = ['X' if coord == '0' else coord for coord in printready]
What I would like to know is why this works (I understand the logic in the code, not why the compiler accepts this.)
I am also trying to insert the condition "elif" there (for the sake of argument, changing "1" to "Y").
This is probably fully documented, but I have no idea what it's called.
source
share