-
-
Save dketov/b6526b7196ce4984906d49675cbb5e11 to your computer and use it in GitHub Desktop.
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
# -*- encoding: utf-8 -*- | |
def get_dict(keys, values): | |
"""Есть два списка разной длины. В первом содержатся ключи, а во | |
втором значения. Напишите функцию, которая создаёт из этих ключей и | |
значений словарь. Если ключу не хватило значения, в словаре должно | |
быть значение None. Значения, которым не хватило ключей, нужно | |
игнорировать.""" | |
from itertools import imap, ifilter | |
return dict( | |
ifilter( | |
lambda (x, y): x, | |
map( | |
lambda x,y: (x,y), | |
keys, values | |
) | |
) | |
) | |
if __name__ == "__main__": | |
list1 = [1, 2, 3, 4] | |
list2 = ['one', 'two', 'three', 'four', 'five'] | |
print "list1 =", list1 | |
print "list2 =", list2 | |
print "get_dict(list1, list2) =", get_dict(list1, list2) | |
print "get_dict(list2, list1) =", get_dict(list2, list1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment