学校头哥作业7_集合与字典(头哥作业[Python])

7_1集合添加元素

n = input()
try:
    ssn = []
    while True:
        sn = input().strip()
        if sn == '':
            break
        ssn.append(sn)
    print(ssn)
except:
    pass
s = set(ssn)
print(len(s))

7_2字符串去重排序

a= ''.join(sorted(list(set(input()))))
print(a)

7_3字典增加元素

dict1 = {'赵小明': '13299887777', '特明朗': '814666888', '普希京': '522888666', '吴小京': '13999887777'}
name = input()
number = int(input())
if dict1.get(name) == None:
    dict1[name] = number
    for key,value in dict1.items():
        print(f"{key}:{value}")
else:
    print("您输入的姓名在通讯录中已存在")

你可能感兴趣的:(Python作业[头哥],python)