Python Tip #15 (of 365):
Don't forget about slicing!
To get all command-line args but the first, you COULD do this:
import sys
arguments = list(sys.argv)
arguments.pop(0)
But slicing is better for "get all but the first":
import sys
arguments = sys.argv[1:]
Slicing is commonly used to...
Get the first few:
first3 = items[:3]
Get the last few (note the negative):
last3 = items[-3:]
Exclude first or last:
all_but_first = items[1:]
all_but_last = items[:-1]
๐งต(1/2)