python小练习

第一题

list1=[1,3,3,2,4,4]
dict1={}
for key in list1:
    dict1[key]=dict1.get(key,0)+1
print(dict1)

第二题

list1=open('data.txt','r').readlines()
list2=[x.strip() for x in list1 if x.strip()!='']
list3=[i for i in list2 if list2.count(i)>1]
for i in set(list3):
    print(i)
posted @ 2021-02-23 17:53  hank-li  阅读(77)  评论(0编辑  收藏  举报