What is the Pythonic way to find the longest common prefix of a list of lists?

os.path.commonprefix() works well for lists 🙂

>>> x = [[3,2,1], [3,2,1,4,5], [3,2,1,8,9], [3,2,1,5,7,8,9]]
>>> import os
>>> os.path.commonprefix(x)
[3, 2, 1]

Leave a Comment