I need to split a list into halves such that if it has an odd length the middle element is ignored entirely, I have a function for this, but it's quite slow for what I'm trying to do.
My function (variables renamed because they make no sense out of context):
def splitList(array):
half = len(array)/2
if len(array)%2==0:
return array[:half], array[half:]
else:
return array[:half], array[half+1:]
This function has to be called about 17 million times if my estimations are correct, so it has to be rather faster. Since I'm new to this though, if you could explain why your answer works faster, that would be perfect :)
last-minute thingy: it's for a small part of a projectEuler challenge if you were wondering, you're supposed to be able to get an answer in under a minute is why it has to be so fast.