Posts

Showing posts from March, 2021

For-Else in Python - who knew?

I love that I am still discovering Python functionality, even after coding daily for six years. This week I learnt that else clauses aren't just for if statements - they can be added to loops! The else clause will trigger if and only if the loop completed without being broken. For instance, this snippet will will print the numbers zero through nine then print 'Done!': for i in range(10): print(i) else: print('Done!') The main use case is handling a break clause in your loop not triggering, for instance: for number in [3,5,7,9,11]: if number % 2 == 0: print('Found an even number!') break else: print('No even numbers found!') This isn't an uncommon situation to want to handle and the else clause makes it so much neater.

Oxford or Cambridge? A West-East divide!

I've been around Oxford and Cambridge for a decade now: I did my undergrad and PhD at Cambridge before jumping ship for a Junior Research Fellowship at Oxford. You meet people from all over the UK at both universities, but I've always had an impression that people from different parts of the UK were more likely to apply to one or the other. As a teenager in Scotland it felt obvious that I'd apply to Cambridge, while it was equally obvious that the 'posh' South-Englanders would apply to Oxford. I've recently been experimenting with the Bokeh  interactive visualisation library so I decided to put my subjective impressions to the test. I took the number of applications from each region over 2017-2019 from the admissions websites of both universities, then computed the fraction of Oxbridge applicants from each region who applied to Cambridge. The visualisation below is surprisingly interactive: you can zoom, pan, and hover over regions to see the exact numbers. ...