[cell.replace("--","hello") if cell=="--" else cell for cell in row]
When using the if
at the end of the for
, it restricts which items are considered, so that version will only return one item, since only one item in the source list matches the condition.
Also in this case you don't need to use replace
, you could just use "hello" if cell=="--"
instead, but you would use this form if you had multiple items you wanted to manipulate.