Python作业记录

复制过来的代码的换行有问题,但是也不是什么大问题。

后续我会进行补充和修改。

请将如下英文短句根据单词切分成列表:

'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}

计算字典中值为偶数的键的总和。


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值