zip(), dict(), itertools.repeat(), list(迭代器)

*. zip(), dict()
def demo_zip_dict():
    keys = ['a', 'b', 'c']
    values = [1, 2, 3]
    entrys = zip(keys, values)
    print(entrys)
    dictionary = dict(entrys)
    print(dictionary)
----
[('a', 1), ('b', 2), ('c', 3)]
{'a': 1, 'c': 3, 'b': 2}

*. itertools.repeat()
def demo_iter_repeat():
    repeat_versions = itertools.repeat("0.0.1")
    images = ("a", "b")
    dic = dict(zip(images, repeat_versions))
    print(dic)
    print(list(dic))
----
{'a': '0.0.1', 'b': '0.0.1'}
['a', 'b']

*. list做用於迭代器,將其轉換爲list。
list(self.__apps.items())
相關文章
相關標籤/搜索