0002python中dict和list的特殊构造

>>> myinfor = {"name":"qiwsir","site":"qiwsir.github.io","lang":"python"}

>>> dict(zip(myinfor.values(),myinfor.keys()))

'qiwsir''name', 'python''lang', 'qiwsir.github.io''site'}

>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']

>>> list(enumerate(seasons))

[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]

>>> list(enumerate(seasons, start=1))

[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]

>>> squares = [x**2 for x in range(1,10)]

>>> squares

[1, 4, 9, 16, 25, 36, 49, 64, 81]

原文地址:https://www.cnblogs.com/zftylj/p/python0002.html