复制过来的代码的换行有问题,但是也不是什么大问题。
后续我会进行补充和修改。
请将如下英文短句根据单词切分成列表:
'The continent of Antarctica is rising. It is due to a geological phenomenon called post-glacial uplift'
并在切分好的列表中找到长度最长的单词。
def changDu(t):
return len(t)
Jvzi='The continent of Antarctica is rising. It is due to a geological phenomenon called post-glacial uplift'
P=Jvzi.split()
P.sort(key=changDu,reverse=1)
print(P[0])
设置列表L1 = [1, 2, 3, 11, 2, 5, 3, 2, 5, 33, 88]
取出列表中最大的三个值。
L1 = [1, 2, 3, 11, 2, 5, 3, 2, 5, 33, 88]
L2 = [] #放最大的三个数
L3 = L1.copy() #备份
L4 = [] #存放原顺序的L1但是没有L2
L1.sort()
num=3
while num>0:
num-=1;
L2.append(L1.pop())
for x in L3:
if( x not in L2):
L4.append(x)
L1 = L4.copy()
print(L1)
print(L2)
将('a', 'b', 'c', 'd', 'e') 和 (1,2, 3, 4, 5)两个元组
转成以(1, 2, 3, 4, 5)为key, ('a', 'b', 'c', 'd', 'e') 为value的字典。
a=('a', 'b', 'c', 'd', 'e')
b=(1,2, 3, 4, 5)
c=zip(a,b)
print(dict(c))
计算字典中值为偶数的键的总和
已知字典sample_dict = {'a': 3, 'b': 4, 'c': 5, 'd': 6}
计算字典中值为偶数的键的总和。