2019-01-25 21:04:34 Python

リスト内の共通接頭辞を求める

Copy Copied! Full
A = ["abc", "abcd", "abcde"] prefix = [] # Up to the smallest number of elements. e.g. "abc" for x in zip(*A): # Unpacking if len(set(x)) == 1: prefix.append(x[0]) else: break print("".join(prefix))
リスト内の共通接頭辞を求める
RECOMMEND