'''编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 ""。'''
def longestCom(strs): pre = '' for i in zip(*strs): if len(set(i))==1: pre+=i[0] else: break return preif __name__ == '__main__': a = longestCom(strs=["flower","flow","flight"]) print(a)