I have a list and a function that is built for the list. how to make the function run? How to properly understand the meaning of self in this function?
strs = ["flower","flow","flight"]
def longestCommonPrefix(self, strs):
longest_pre = ""
if not strs: return longest_pre
shortest_str = min(strs, key=len)
for i in range(len(shortest_str)):
if all([x.startswith(shortest_str[:i+1]) for x in strs]):
longest_pre = shortest_str[:i+1]
else:
break
return longest_pre
if I run the code as follow:
longestCommonPrefix(strs)
it shows:
TypeError: longestCommonPrefix() missing 1 required positional argument: 'strs'