While these answers may work for the specific case of the OP, I found they weren't suitable for broader application.
Here are the methods I could think of/saw here and their respective timings.
Negative Slice Method 1
for x in urlist[:-1]:
pass
# <- handle last item here
Negative Slice Method 2
last_item = urlist[-1]
for x in urlist:
if x == last_item:
pass
Enumerate Method
urlist_len = len(urlist)-1
for index, x in enumerate(urlist):
if index == urlist_len:
pass
Results:
┌─────────────────────────┬───────┬───────┬───────┐
│ list size │ 10**2 │ 10**4 │ 10**8 │
├─────────────────────────┼───────┼───────┼───────┤
│ negative slice method 1 │ 2e-6 │ 2e-4 │ 3 │
│ negative slice method 2 │ 1e-6 │ 1e-4 │ 1 │
│ enumerate │ 2e-6 │ 2e-4 │ 2 │
└─────────────────────────┴───────┴───────┴───────┘
The negative slice method 2 is the fastest in all cases, but if you have duplicate items in your list, negative slice method 2 will give you a false positive. Also, the negative slice method requires that the sequence you are iterating over supports indexing. So, in the case of duplicate items in your list (or not index supporting sequence) use the enumerate method.
Depending on the body your loop, negative slice method 1 or 2 may result in simpler code and they are close in performance.