Is there any way to prevent ear infections after swimming?

Swimming in a pool, lake, or ocean and letting the water stay in the ear can change the acidity in the ear canal, making it more prone to infection from whatever bacteria are lurking in the water.