目录
7-1 求出歌手的得分
n=int(input())
lo=[int(n) for n in input().split()]
lo.sort()
for i in range(0,4):
num1=lo.pop(-1)
lo.reverse()
sum=0
for j in range(len(lo)):
sum+=lo[j]
li=sum/len(lo)
print("aver={:.2f}".format(li))
7-2 输出字母在字符串中位置索引
str = input()
a, b = input().split()
i = len(str) - 1
str = str[::-1] #字符串反向
for ch in str:
if ch == a or ch == b:
print(i, ch)
i -= 1
7-3 字典合并
a = dict(eval(input()))
b = dict(eval(input()))
for k in b.keys():
a[k] = a.get(k, 0) + b[k]
t = list(a.items())
t.sort(key=lambda x : ord(x[0]) if type(x[0]) == str else x[0])
c = str(dict(t)).replace(' ', '').replace("'", '"')
print(c)
7-4 通过两个列表构建字典
keys_list = input().split()
values_list = input().split()
temp_dict = {}
for i in range(0, len(keys_list)):
temp_dict[keys_list[i]] = values_list[i]
keys_list.sort()
final_dict = {}
for i in range(0, len(keys_list)):
final_dict[keys_list[i]] = temp_dict[keys_list[i]]
result = []
for i in range(0, len(keys_list)):
result.append((keys_list[i], final_dict[keys_list[i]],))
print(result)
7-5 jmu-python-重复元素判定
n=eval(input())
false=true=0
for i in range(n):
list=input()
lista=[]
lista=list.split()
if len(lista) == len(set(lista)):
false+=1
else:
true+=1
print("True={}, False={}".format(true,false))
7-6 求集合的最大值和最小值
dic=[-32,3,-55,234,21]
print('{',end = '')
print(', '.join(str(i)for i in dic),end='')
print('}')
print(max(dic))
print(min(dic))
7-7 字符替换
s = input()
result = ""
for i in s:
if i.isupper():
i = chr(ord('A') + ord('Z') - ord(i))
result += i
else:
result += i
print(result)
7-8 合并成绩
a = tuple(map(int,input().split(',')))
b = tuple(map(int,input().split(',')))
alls = a+b
str1 = ' ' + ' '.join(f'{s:2}' for s in alls)
print(str1)