Skip to content

Instantly share code, notes, and snippets.

@yv84
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save yv84/43ed7e59eed6b793e15b to your computer and use it in GitHub Desktop.

Select an option

Save yv84/43ed7e59eed6b793e15b to your computer and use it in GitHub Desktop.
# https://company.yandex.ru/job/vacancies/dev_pyth_transport.xml
from itertools import chain
def f(l1, l2):
def gen():
while True:
yield None
return dict(zip(l1, chain(l2, gen())))
assert(f([1,2,3,4,5,6],['a','b','c']) ==
{1: 'a', 2: 'b', 3: 'c', 4: None, 5: None, 6: None})
#---------------------------
#---------------------------
import re
def check_psw1(psw):
r = re.compile(r"""(?x)(?i)
^
(([a-zA-Z])
||
([a-zA-Z][a-zA-Z0-9\.-]{0,18}[a-zA-Z0-9]))
$""")
return bool(r.match(psw))
# --
from itertools import chain
from functools import reduce
import string
def check_psw2(psw):
return reduce(
lambda a,i: a and i,
chain(
[len(psw) <= 20],
[i in set("".join(
(string.ascii_letters))
) for i in psw[0]],
[i in set("".join(
(string.ascii_letters, string.digits, ".-"))
) for i in psw[:]],
[i in set("".join(
(string.ascii_letters, string.digits,))
) for i in psw[-1]]),
True)
psw_true = ['a', 'A', 'aa.-a', 'aa123', 'a'*20, ]
psw_false = ['1', '.', '$aa', 'a_', '-aaa', 'aa.#a', 'a'*21, 'aaa.', 'aaa-']
for ii in psw_true:
assert(check_psw1(ii))
assert(check_psw2(i))
for ii in psw_false:
assert(not check_psw1(ii))
assert(not check_psw2(ii))
@yv84
Copy link
Copy Markdown
Author

yv84 commented Sep 7, 2014

map(None, a, b)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment