def commonPrefix(completions):
 def cp(str1, str2):
  '\n        :return: the longest common prefix for 2 strings.\n        '
  ls2 = len(str2)
  j = 1
  for i in range(len(str1)):
   if ((i >= ls2) or (str1[i] != str2[i])):
    j = 0
    break
  result = str1[:(i + j)]
  return result
 strs = [v[len(p):] for (p, v) in completions]
 if (len(strs) == 0):
  return ''
 if (len(strs) == 1):
  return strs[0]
 (result, tail) = (strs[0], strs[1:])
 for i in range(len(tail)):
  result = cp(result, tail[i])
  if (result == ''):
   break
 return result

def commonPrefix ( completions ) : def cp ( str1 , str2 ) : ls2 = len ( str2 ) j = 1 for i in range ( len ( str1 ) ) : if ( ( i >= ls2 ) or ( str1 [ i ] != str2 [ i ] ) ) : j = 0 break result = str1 [ : ( i + j ) ] return result strs = [ v [ len ( p ) : ] for ( p , v ) in completions ] if ( len ( strs ) == 0 ) : return '' if ( len ( strs ) == 1 ) : return strs [ 0 ] ( result , tail ) = ( strs [ 0 ] , strs [ 1 : ] ) for i in range ( len ( tail ) ) : result = cp ( result , tail [ i ] ) if ( result == '' ) : break return result
utility function which is used by console to extract the string to be suggested as autocompletion .