You could use LabelBinarizer or label_binarize from the preprocessing module.