Python-字典生成式and字典小结
内置函数zip()
用于将可迭代的对象作为参数,将对象中对应的元素打包成一个元组,然后返回有这些元组组成的列表。
字典小结:
1 items = ['Fruits', 'Books', 'Others'] 2 prices = [96, 78, 85] 3 4 # .upper()变大写 5 # .lower()变小写 6 # .capitalize()首字母大写 7 # .title()每个单词首字母都大写 8 d = {item.upper():price for item,price in zip(items,prices) } 9 print(d) 10 11 s = 'kiss the girl' 12 print(s.title())