Skip to content

Instantly share code, notes, and snippets.

import csv
collisions = list(csv.DictReader(open('dft-road-casualty-statistics-collision-1979-latest-published-year.csv')))
print("Row count, 1979-present:", len(collisions))
fatal_collisions = [row for row in collisions if row['collision_severity'] == '1']
print("Of those,", len(fatal_collisions), "were fatal")
correct_years_collisions = [row for row in fatal_collisions if 2005 <= int(row['collision_year']) <= 2018]
@ExplodingCabbage
ExplodingCabbage / simulation.py
Last active January 5, 2020 19:37
Monty Hall Problem Monte Carlo simulation
# A simulation to settle a Twitter argument:
# https://twitter.com/brenorb/status/1213898659752038400
import random
random.seed(42) # For reproducible results
# We have four possible scenarios we can simulate, based on these two bools.
# The first determines whether it's permissible for the host to reveal the car
# on the first door-opening. The second determines whether the contestant is
# using an "always swap" strategy or an "always stick" strategy.