L=[('Alice',89),('Bob',72),('Candy',88),('David',79),('Ellena',99)]
print(sorted(L,key=lambda x:x[1],reverse=True))
print(sorted(L,key=lambda x:x[1],reverse=True))
2022-03-10
最赞回答 / weixin_慕圣3493772
是的。L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]for cube in L:#对每个一维数组,计算其三个边的成绩之和的两倍就是表面积 area=(cube[0]*cube[1]+cube[1]*cube[2]+cube[0]*cube[2])*2 print(area)
2022-03-09
L = [75, 92, 59, 68, 99]
sum =0
a=0
for x in L:
sum=sum+x
a=a+1
print(sum/a)
sum =0
a=0
for x in L:
sum=sum+x
a=a+1
print(sum/a)
2022-03-05
template = "hello life is {s}, hello you need {p}."
s = "short"
p = "python"
result = template.format(s = "short", p = "python")
print(result)
s = "short"
p = "python"
result = template.format(s = "short", p = "python")
print(result)
2022-03-05
q= r"'\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.'"
print(q)
print(q)
2022-03-05
list1=[]
set1=set(list1)
c1=['Jenny','Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
for name in c1:
set1.add(name)
print(set1)
或
list1=[]
set1=set(list1)
c1=['Jenny','Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
set1.update(c1)
print(set1)
set1=set(list1)
c1=['Jenny','Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
for name in c1:
set1.add(name)
print(set1)
或
list1=[]
set1=set(list1)
c1=['Jenny','Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
set1.update(c1)
print(set1)
2022-03-04
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
name_set = set(names)
print('请输入查询名字')
p=input()
s=p.lower()
for name in name_set:
if s in name.lower():
print('存在')
break
else:
print('不存在')
name_set = set(names)
print('请输入查询名字')
p=input()
s=p.lower()
for name in name_set:
if s in name.lower():
print('存在')
break
else:
print('不存在')
2022-03-04
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
n=0
for key,value in d.items():
n=n+1
print(n)
n=0
for key,value in d.items():
n=n+1
print(n)
2022-03-04
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for key in d:
p=d[key]
n=0
while n <3:
print(key,p[n])
n=n+1
或
for key,v in d.items():
n=0
while n <3:
print(key,v[n])
n=n+1
for key in d:
p=d[key]
n=0
while n <3:
print(key,p[n])
n=n+1
或
for key,v in d.items():
n=0
while n <3:
print(key,v[n])
n=n+1
2022-03-04
最赞回答 / 慕斯卡8373086
def square_of_sum(L): result = [] for i in L: result.append(i*i) return resultd = [1,2,3,4,5]r = square_of_sum(d)print(r)我是这样写的
2022-03-03
已采纳回答 / 小颖April
因为有重合返回false,所以flag的值为假,not flag就为真,所以if not flag就是为了进入这个条件判断,接下来的操作就是打印重复元素了
2022-03-03