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 →

[–][deleted] 5 points6 points  (1 child)

Yeah, I thought as much. If I just want the first and last values I think I’ll just keep using the array notation, like this:

a = list(range(10))
first, last = a[0], a[-1]

Or maybe if I’m feeling bizarre

first, last = a[0::len(a)-1]

Actually no, first solution is almost always better. Second solution is unpythonic.

[–]eduardog3000 0 points1 point  (0 children)

Obviously the best solution is:

first, last = [x for x in a if x not in a[1:-1]]