# 让字典保持有序
from mrjob.py2 import xrange
from pip._vendor.distlib.compat import raw_input
d = {}
d['Jim'] = (1, 35)
d['Leo'] = (2, 37)
d['Bob'] = (3, 40)
for k in d:
print(k)
from collections i...
from functools import reduce
from random import randint, sample
# 获取多个字典中相同的key
data1 = sample('abcdefg', 3)
print(data1)
data2 = sample('abcdefg', randint(3, 6))
print(data2)
s1 = {x: randint(1, 4)...
from random import randint
d = {x: randint(60, 100) for x in 'xyzabc'}
print(d)
# 将字典转化为元组, 第一种方式
d2 = list(zip(d.values(), d.keys()))
print(sorted(d2))
# 第二种方式
d3 = d.items()
print(d3)
...
from random import randint
from mrjob.py2 import xrange
# 列表筛选大于0的数
# 常用写法
data = [1, 5, -3, -2, 6, 0, 9]
res = []
for x in data:
if x >= 0:
res.append(x)
print(res)
# 生成...