6.检查传入字典的每一个value的长度,如果大于2,那么仅保留前两个长度的内容,并将新内容返回给调用者。
dic = {"k1": "v1v1", "k2": [11,22,33,44]} PS:字典中的value只能是字符串或列表 dic = {"k1": "v1v1", "k2": [11,22,33,44]} def func(dic1): for i,j in dic1.items(): if len(j) > 2: dic1[i] = j[:2] else: dic1[i] = j return dic1 print(func(dic))