Skip to content

Instantly share code, notes, and snippets.

@tsuyukimakoto
Last active June 22, 2019 03:27
Show Gist options
  • Save tsuyukimakoto/0a2015114607fdde212335bb578e0ae2 to your computer and use it in GitHub Desktop.
Save tsuyukimakoto/0a2015114607fdde212335bb578e0ae2 to your computer and use it in GitHub Desktop.
assignable expression and regex
import re
def check(passwd):
if (password_length := len(passwd)) < 1:
return 'Need password'
if (m := re.search(r'^%s+' % passwd[0], passwd)) and m.span()[1] == password_length:
return '{0} contains only same character'.format(passwd)
return '{0} is suitable for password'.format(passwd)
if __name__ == '__main__':
print(check(''))
print(check('aaaa'))
print(check('aaac'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment