• hash算法的移到面试题


    一家公司的员工管理系统,记录员工姓名,性别,年龄,部门,若员工内部转岗 例如python开发转到go开发,产生新的记录,姓名,性别,年龄,新的部门

    假设有一千个员工,如果几个员工的姓名和性别相同,那么认为是同一个员工,请对这一千个员工去重

     1 class Employee:
     2     def __init__(self, name, age, sex, partment):
     3         self.name = name
     4         self.age = age
     5         self.sex = sex
     6         self.partment = partment
     7 
     8     def __hash__(self):
     9         return hash("%s%s" % (self.name, self.sex))
    10 
    11     def __eq__(self, other):
    12         if self.name == other.name and self.sex == other.sex:
    13             return True
    14 
    15 
    16 employee_list = []
    17 for i in range(250):
    18     employee_list.append(Employee('Aqiu', i, 'nan', 'python'))
    19 for i in range(250):
    20     employee_list.append(Employee('qiu', i, 'nan', 'java'))
    21 for i in range(250):
    22     employee_list.append(Employee('A', i, 'nv', 'c++'))
    23 for i in range(250):
    24     employee_list.append(Employee('iu', i, 'nv', 'python'))
    25 
    26 employee_set = set(employee_list)
    27 for person in employee_set:
    28     print(person.__dict__)
    View Code
  • 相关阅读:
    Vasya and Endless Credits CodeForces
    Dreamoon and Strings CodeForces
    Online Meeting CodeForces
    数塔取数 基础dp
    1001 数组中和等于K的数对 1090 3个数和为0
    1091 线段的重叠
    51nod 最小周长
    走格子 51nod
    1289 大鱼吃小鱼
    POJ 1979 Red and Black
  • 原文地址:https://www.cnblogs.com/-Aqiu/p/13131590.html
Copyright © 2020-2023  润新知