Code in managed, dynamically typed languages spends more tokens on doing the actual task and less on managing resources and satisfying the compiler. (Explicit type information might be useful for "reasoning" AI systems, but the job seems overall easier when it isn't actually forced to do the type calculus.) Plus Python reads more like a natural language overall, especially since it isn't using as many non-verbal tokens like closing braces to indicate the end of a scope. Plus there's a ton of example Python code out there
specifically in contexts where people are talking about programming and explaining what the code is supposed to do.
I don't think it's at all surprising that LLMs have learned (whatever that means) Python (and JavaScript) better than other programming languages.