def is_valid_device(dev):
 regex = re.compile('/dev/sd[a-z]$')
 try:
  return (regex.match(dev) is not None)
 except TypeError:
  return False

def is_valid_device ( dev ) : regex = re . compile ( '/dev/sd[a-z]$' ) try : return ( regex . match ( dev ) is not None ) except TypeError : return False
checks that dev matches the following regular expression: /dev/sd[a-z]$ .