dict_1 = {'apple': 9, 'banana': 6}
dict_2 = {'banana': 4, 'orange': 8}
#python3的新方法
combined_dict = {**dict_1, **dict_2}
print(combined_dict)
#{'apple': 9, 'banana': 4, 'orange': 8}
- 有时候,你不知道你当前列表的嵌套深度,但是你希望把他们展开,放到一维的列表中
#先要安装iteration_utilities
pip install iteration_utilities
from iteration_utilities import deepflatten
l = [[1,2,3],[4,[5],[6,7]],[8,[9,[10]]]]
print(list(deepflatten(l)))
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
my_string = "ABCDE"
reversed_string = my_string[::-1]
print(reversed_string)
#EDCBA
my_list = ["a", "b", "c"]
for index,n in enumerate(my_list, 5):
print(index,n)
#5 a
#6 b
#7 c
网友评论