上证所python笔试题【多测师_王sir】
#coding=utf-8 """ =========================== Author:多测师_王sir Time:2020-12-11 12:00 Wechat:xiaoshubass website:www.duoceshi.cn =========================== """ 第一题: l = [{'a': 'duoceshi', 'b': 'dcs8'}, {'a': 'duoceshi8', 'b': 'dcs8'}, {'a': 'duoceshi', 'b': 'dcs8'}] def remove_dict(): ''' 去除字典列表中的重复字典 :return: ''' set1 = set() list1 = [] for d in l: t = tuple(d.items()) if t not in set1: set1.add(t) list1.append(d) print(list1) remove_dict() #调用结果如下: [{'a': 'duoceshi', 'b': 'dcs8'}, {'a': 'duoceshi8', 'b': 'dcs8'}] 第二题: import time def count_time(func): def int_time(*args, **kwargs): start_time = time.time()#这个是程序开始时间 func() over_time = time.time()#这个是程序结束时间 total_time = over_time - start_time print('程序共计%s秒' % total_time) return int_time @count_time def main(): print('>>>>开始计算函数运行时间') for i in range(1, 100): # 可以是任意函数 , 这里故意模拟函数的运行时间 for j in range(i): print(j) if __name__ == '__main__': main() 运行结果如下: 程序共计0.036902666091918945秒