def is_valid_git_sha1(hash):
 if (len(hash) != 40):
  return False
 try:
  value = int(hash, 16)
 except ValueError:
  return False
 return True

def is_valid_git_sha1 ( hash ) : if ( len ( hash ) != 40 ) : return False try : value = int ( hash , 16 ) except ValueError : return False return True
check if a string is a valid git sha1 string input: hash: string to validate output: true if the string has 40 characters and is an hexadecimal number .