Created
November 30, 2014 12:20
-
-
Save RaD/87fdf30b515a10c50417 to your computer and use it in GitHub Desktop.
В системе аутентификации есть ограничение: логин должен начинаться с латинской буквы, состоять из латинских букв, цифр, точки и минуса, но заканчиваться только латинской буквой или цифрой; минимальная длина логина — один символ, максимальная — 20. Напишите код, проверяющий соответствие входной строки этому правилу.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| a = 'a' | |
| b = 'a12-4b' | |
| c = '1234vvv' | |
| d = 'afdf23-' | |
| e = 'asd1_2a' | |
| f = 'abcdeffwcflszsafdibcawerxbweiowberqwrrwrxe' | |
| g = 'asd1.2a' | |
| letters = 'abcdefghijklmnpqrstuvwxyz' | |
| digits = '1234567890' | |
| edges = list(letters) | |
| allowed = list(letters+digits+'.-') | |
| def check(v): | |
| v = v.lower() | |
| return \ | |
| 0 < len(v) < 21 and \ | |
| v[0] in edges and \ | |
| v[-1] in edges and \ | |
| set(v) == set(v).intersection(allowed) | |
| for i in [a, b, c, d, e, f, g]: | |
| print i, check(i) | |
| # a True | |
| # a12-4b True | |
| # 1234vvv False | |
| # afdf23- False | |
| # asd1_2a False | |
| # abcdeffwcflszsafdibcawerxbweiowberqwrrwrxe False | |
| # asd1.2a True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment