zip - used for iterating over multiple lists.
*strs - for making multiple lists out of a single list
Hence, the loop will iterate over 1st character in all the elements then second and so on...
A set of such a string will have a single character if its a common prefix across all the strings.
Hence we can break from the loop once this trend ends.
Hope the explanation helps!
if not strs: return "" count=0 for letter_group in zip(*strs): if(len(set(letter_group))>1): break count = count + 1 return(strs[0:count])