Cleaning up conditionals

Chris Angelico rosuav at gmail.com
Sat Dec 31 17:18:30 EST 2016


On Sun, Jan 1, 2017 at 9:03 AM, Deborah Swanson
<python at deborahswanson.net> wrote:
> And didn't finish it because I couldn't see what a should be. I want it
> to be
> l2[v] if the first clause is true, and l1[v] if the second. If I was
> computing a value, this would work beautifully, but I don't see how it
> can if I'm choosing a list element to assign to. Maybe I just can't see
> it.

It's possible to select either l1 or l2 using an expression, and then
subscript that with [v]. However, this does not usually make for
readable code, so I don't recommend it.

(l1 if whatever else l2)[v] = new_value

ChrisA


More information about the Python-list mailing list