Had trouble with the list comprehension part.

Went ahead and did it with a loop. Couldn't get the different syntax to work using a list comprehension for avgAgeByGender.
You're putting chunks of functionality into functions, but using global variables throughout so that the effect is exactly the same as just running through the contents of each function in turn. There is some benefit just in chunking things this way so that you can see the overall flow in summary, but you'll probably want to design functions that take arguments and return values.