the longer a key is pressed down, the higher a counter for said key increases
Unless your users have 300 fingers, they likely would only be pressing up to ten keys at a time. You can register for keydown and keyup events; save the frame counter or the return value of time()/clock() on the array when a key is down; and when a key is up or when you need to find the current value of the key, subtract the differences. This will reduce the number of loops to around 10 rather than 300. Note that depending on the system, time()/clock() may be a syscall, which can be slow, so using frame counter may be preferable.
counter = 0
keys = {}
while True:
for event in pygame.event.get() :
if event.type == pygame.KEYDOWN :
keys[event.key] = counter
elif event.type == pygame.KEYUP :
diff[event.key] = keys.pop(event.key) - counter
counter += 1
But I highly doubt that this is the bottleneck of your game.