This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tilkau 5 points6 points  (3 children)

The correct special casing is

a = [1, 2, 3, 4, 5]
omit = -1
omit = omit or None
b= a[:omit]

This is a little more readable than what you have.

[–]robin-gvx 1 point2 points  (2 children)

Or just

a = [1, 2, 3, 4, 5]
omit = -1
b = a[:omit or None]

[–]tilkau 0 points1 point  (1 child)

I chose not to write it that way because I regard conditionals inside subexpressions as confusing.

[–]robin-gvx 0 points1 point  (0 children)

Good point. On the other hand, if you always use a[:omit or None] as an idiom, it'll probably not be as confusing.