python 拼音性命按照姓出现的次数排序_Python按姓氏排序字典列表
我试图对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按姓氏排序字典列表相关推荐
- python八大选择排序_Python实现选择排序
选择排序: 选择排序(Selection sort)是一种简单直观的 排序算法 .它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最 ...
- python选择排序_Python实现选择排序
选择排序: 选择排序(Selection sort)是一种简单直观的 排序算法 .它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最 ...
- python dataframe排序_python – Pandas DataFrame排序忽略了这种情况
我在 Python中有一个Pandas数据帧.数据帧的内容来自 here.我稍微修改了"单个"列中第一个字母的大小写.这是我有的: import pandas as pd df = ...
- python列表数据排序_Python中,如何将列表中数据排序给列表排序?
在程序中使用字典进行数据信息統计时由于字典是无序的所以打印字典时内容也是无序的.因此为了使统计得到的结果更方便查看需要进行排序.Python中字典的排序分为按"键"排序和按&quo ...
- python用户输入字符串串从小到大排序_python字符串从小到大排序
python字符串排序问题 a='AADFabddefgilmrsss' 请将该字符串a里的单词重新排序(a-z),并且重def char_cmp(a, b): #实现你的比较规则, 分太少,不值为你 ...
- python字母大小写排序_Python中sorted()排序与字母大小写的问题
今天我在练习python时,对字典里的键用sorted排序时发现并没有按照预期排序 研究后发现字母大小写会影响排序 首先创建一个字典,键里面的首字母有大写有小写 favorite_digit = { ...
- python编程单词排序_Python编程20:字典的遍历和排序
#少儿编程# 字典的遍历 1)通过遍历key来遍历字典 所谓遍历,简单点就说就是所有的值都访问一遍.Python字典的遍历有几种方式: 遍历key有两种方式.一种如图1中的红框内的代码: 图1 for ...
- python去重复排序_Python实现删除排序数组中重复项的两种方法示例
本文实例讲述了Python实现删除排序数组中重复项的两种方法.分享给大家供大家参考,具体如下: 对于给定的有序数组nums,移除数组中存在的重复数字,确保每个数字只出现一次并返回新数组的长度 注意:不 ...
- python 列表自动排序_Python学习小技巧之列表项排序的示例代码分享
这篇文章主要给大家介绍了Python学习小技巧之列表项排序的相关资料,文中介绍的非常详细,需要的朋友们可以参借鉴,下面跟着小编一起来学习学习吧. 本文介绍的是关于Python列表项排序的相关内容,分享 ...
- python大文件排序_Python 大文件排序
1.[代码][Python]代码 import gzip import os from multiprocessing import Process, Queue, Pipe, current_pro ...
最新文章
- xsd文件转图片_图片转换成PDF格式怎么转?图片转换成PDF的软件哪个好?
- 「技术综述」如何降低遮挡对人脸识别的影响
- Android10.0应用进程创建过程以及Zygote的fork流程-[Android取经之路]
- Eclipse里如果看不到Attach Source按钮应该怎么办
- python如何自定义函数_python如何自定义函数_后端开发
- IDC:第一季度全球服务器市场收入下滑4.6% 市场为重大升级做准备
- 5G毫米波通信中一些量化的概念
- 测试用例又双叒叕失败了,NLP帮你
- Ubuntu/Mac彻底解决手机ADB识别问题
- pyspider all 只启动了_Python 爬虫:Pyspider 安装与测试
- 为什么说ES6的class是语法糖?
- ActiveMQ笔记(二)
- eclipse黑色炫酷主题设置1
- OpenCV实现人脸对齐
- wps怎么打包图片_wps如何压缩图片
- 机器人学领域的顶级期刊和会议
- 一篇关于批处理文件的经典文章
- 华为手机鸿蒙更新时间,华为手机版鸿蒙系统更新时间介绍
- 办公小贴士之:Excel奇偶行隔行填充颜色
- 为什么说C++太复杂?复杂的必要性是为什么?