我试图对dep_list进行排序,这是一个包含员工信息(姓名、部门、职位、薪水)的字典列表。现在我想我已经按名字排序了,但是我想按姓氏排序。如果可能的话,不要把“name”分成两个不同的字符串。在#Function for adding employee information

def add_emp():

#Ask the user to add an employee

print("Enter the employee's information:\n")

#Input first and last name

name = str(input("What is the employee's name? ")).title()

#Input employee position

position = str(input("What is their position? ")).title()

#Input employee department

em_department = str(input("What is their department? ")).title()

#Make sure the salary is numeric

try:

#Input employee salary

salary = round(float(input("What is their salary? ")), 2)

#Add information to a dictionary called employees

employees[name] = {"name": name, "position": position, "em_department": em_department, "salary": salary}

except:

print("Salaries must be numeric, silly!")

#Function for adding employees to dictionary by department

def dep_emp():

#Go through all department names stored in the tuple

for x in dep_tup:

#Initialize department list each time to ensure correct sorting

dep_list = []

#Go through all employee dictionaries; when matched, add to the list associated with the corresponding key in the dep_dict dictionary

for names in employees:

if x == employees[names]["em_department"]:

dep_list.append(employees[names])

dep_list.sort(key=operator.itemgetter('name'))

dep_dict[x] = dep_list

continue

注意:字典列表如下所示:

{

部门1:[{'name':姓名,'em_department':部门,'position':职位,'salary':salary},…]

部门2:[…]

}

python 拼音性命按照姓出现的次数排序_Python按姓氏排序字典列表相关推荐

  1. python八大选择排序_Python实现选择排序

    选择排序: 选择排序(Selection sort)是一种简单直观的 排序算法 .它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最 ...

  2. python选择排序_Python实现选择排序

    选择排序: 选择排序(Selection sort)是一种简单直观的 排序算法 .它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最 ...

  3. python dataframe排序_python – Pandas DataFrame排序忽略了这种情况

    我在 Python中有一个Pandas数据帧.数据帧的内容来自 here.我稍微修改了"单个"列中第一个字母的大小写.这是我有的: import pandas as pd df = ...

  4. python列表数据排序_Python中,如何将列表中数据排序给列表排序?

    在程序中使用字典进行数据信息統计时由于字典是无序的所以打印字典时内容也是无序的.因此为了使统计得到的结果更方便查看需要进行排序.Python中字典的排序分为按"键"排序和按&quo ...

  5. python用户输入字符串串从小到大排序_python字符串从小到大排序

    python字符串排序问题 a='AADFabddefgilmrsss' 请将该字符串a里的单词重新排序(a-z),并且重def char_cmp(a, b): #实现你的比较规则, 分太少,不值为你 ...

  6. python字母大小写排序_Python中sorted()排序与字母大小写的问题

    今天我在练习python时,对字典里的键用sorted排序时发现并没有按照预期排序 研究后发现字母大小写会影响排序 首先创建一个字典,键里面的首字母有大写有小写 favorite_digit = { ...

  7. python编程单词排序_Python编程20:字典的遍历和排序

    #少儿编程# 字典的遍历 1)通过遍历key来遍历字典 所谓遍历,简单点就说就是所有的值都访问一遍.Python字典的遍历有几种方式: 遍历key有两种方式.一种如图1中的红框内的代码: 图1 for ...

  8. python去重复排序_Python实现删除排序数组中重复项的两种方法示例

    本文实例讲述了Python实现删除排序数组中重复项的两种方法.分享给大家供大家参考,具体如下: 对于给定的有序数组nums,移除数组中存在的重复数字,确保每个数字只出现一次并返回新数组的长度 注意:不 ...

  9. python 列表自动排序_Python学习小技巧之列表项排序的示例代码分享

    这篇文章主要给大家介绍了Python学习小技巧之列表项排序的相关资料,文中介绍的非常详细,需要的朋友们可以参借鉴,下面跟着小编一起来学习学习吧. 本文介绍的是关于Python列表项排序的相关内容,分享 ...

  10. python大文件排序_Python 大文件排序

    1.[代码][Python]代码 import gzip import os from multiprocessing import Process, Queue, Pipe, current_pro ...

最新文章

  1. 服务端如何防止订单重复支付!
  2. 达观杯_构建模型(一)linearSVM
  3. Pod Preset玩转K8S容器时区自动配置
  4. Mac下如何查看Python的版本?
  5. 用python多个关键字查找_python 如何实现并行查找关键字所在的行?
  6. 第1章python基础语法1
  7. spring3: 4.4 使用路径通配符加载Resource
  8. goland设置Terminal
  9. 继13吨快递烧成灰后 “双11奇葩收件名”又热搜了...
  10. 【ArcGIS】数据属性重新赋值
  11. CashFiesta 攻略
  12. appleid注册服务器错误,连接apple id 服务器时出错(Apple ID 验证连接失败,试试这招)...
  13. 详解网关和路由器的区别
  14. 一键生成?从照片生成人脸 3D 模型 #AvatarMe
  15. Mac上AI照片编辑工具:Luminar AI
  16. word,ppt等office文档转化为pdf进行展示(POI + iText)(亲测有效)
  17. uni-app对接支付
  18. WGCLOUD和ZABBIX有什么不一样
  19. Rancher hosted Kubernetes AKS
  20. 数据库迁移 | DBMotion v23.04 支持异地多活

热门文章

  1. UI设计原型交互基础
  2. 电脑长时间睡眠会自动关机吗_电脑睡眠久了是不是自动关机
  3. excel快速选择多行数据
  4. FPGA数字时钟计数器
  5. Tensorflow2.5(gpu)+Python3.9+Spyder5的平台搭建
  6. perl uc,lc,ucfirst,lcfirst的用法
  7. 解决mac上复制粘贴失效问题
  8. UGNX1953~1980版本怎么测量重量
  9. 笔记本win10玩红警黑屏_你的红警还黑屏吗?
  10. php编网页版计算器,php编程实现简单的网页版计算器功能