当前位置:   article > 正文

学校头哥作业7_集合与字典(头哥作业[Python])_字典增加元素python头歌

字典增加元素python头歌

7_1集合添加元素

  1. n = input()
  2. try:
  3. ssn = []
  4. while True:
  5. sn = input().strip()
  6. if sn == '':
  7. break
  8. ssn.append(sn)
  9. print(ssn)
  10. except:
  11. pass
  12. s = set(ssn)
  13. print(len(s))

7_2字符串去重排序

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

7_3字典增加元素

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/758158
推荐阅读
相关标签
  

闽ICP备14008679号