After a week off (for various reasons, rain, birthday, etc), I started working out again this morning. I ran my usual 2 miles, did some crunches, and did 20 push ups. I’m hoping to get a good ride in tomorrow, the forecast says only a 20% chance of rain.
I was interested in the relative performance of reversing a python list using the idom list[::-1] rather than the reverse method of the list class. Additionally I wanted to see if this idom was efficient for reversing strings compared to converting to a list, reversing that list, and joining the elements again using ''.join(reversed_list). Here are the results:
Reverse list, slicing: (0.58000000000000007, 0.64144396781921387)
Reverse list, method: (0.20000000000000018, 0.19551301002502441)
Reverse string, slicing: (0.45000000000000001, 0.49545693397521973)
Reverse string, list: (3.71, 3.7981550693511963)
Read more…