Skip to content

Instantly share code, notes, and snippets.

@willwest
willwest / longest_common_suffix.py
Last active June 6, 2023 13:20
Longest Common Suffix - Python
import os
# Return the longest common suffix in a list of strings
def longest_common_suffix(list_of_strings):
reversed_strings = [' '.join(s.split()[::-1]) for s in list_of_strings]
reversed_lcs = os.path.commonprefix(reversed_strings)
lcs = ' '.join(reversed_lcs.split()[::-1])
return lcs
@willwest
willwest / GridCV_scores_printer.py
Last active January 27, 2023 11:32
Export a CSV file of GridSearchCV scores.
import csv
import numpy as np
from sklearn.grid_search import GridSearchCV
def print_GridCV_scores(gs_clf, export_file):
'''Exports a CSV of the GridCV scores.
gs_clf: A GridSearchCV object which has been fitted
export_file: A file path