我有这个作为一个家庭作业问题,并不知道我应该如何去做。Python搜索数据集
首先,我给了一个数据集,其中包含员工姓名,地址,电子邮件等清单,共有约50名员工。
你被要求写一个应用程序来提供有关员工的信息。你的程序应该提示用户输入搜索条件。谁与搜索标准匹配的工作人员中的任何成员应打印在屏幕上以下面的格式:
Position Designation Room and Extension Name and Email Address
(列是制表符分隔)Matching信息.......... ..
您将不得不修改数据集进行处理,并且您可以选择将其保存在单独的文件中,但这不是必需的。您的程序应该满足一定的限制条件:
- 您应该将数据集中的每一列与搜索条件进行比较。
- 比较不应区分大小写。
- 除电子邮件地址外,所有输出都应在首笔资本中。
- 如果找到匹配项,则应打印结果行并且列应全部对齐。
- 如果没有匹配,则应打印一条消息,不要有标题行。
您应该保存(1)您的程序,(2)一段说明您是如何完成数据集的处理的。
你也应该运行你的应用这些测试用例:
- 为“布兰达”
- 搜索所有文书人员搜索。
- 为“BredNa”
- 检索查找卡尔博士的位置
- 哪个办公室尼尔位于?
所以,首先,我应该如何读取这个数据集?我应该将它作为文本文件读取还是创建一个元组,字典?等
staff = [['prof.liam maguire','head of school','academic','MS127','75605','[email protected]'],
['prof. martin McGinnity','director of intelligent systems research centre','academic','MS112','75616','[email protected]'],
['dr laxmidhar Behera','reader','academic','MS107','75276','[email protected]'],
['dr girijesh Prasad','professor','academic','MS137','75645','[email protected]'],
['dr kevin Curran','senior lecturer','academic','MS130','75565','[email protected]'],
['mr aiden McCaughey','Senior Lecturer','academic','MG126','75131','[email protected]'],
['dr tom Lunney','postgraduate courses co-ordinator (Senior Lecturer)','academic','MG121D','75388','[email protected]'],
['dr heather Sayers','undergraduate courses','co-ordinator (Senior Lecturer)','academic','MG121C','75148','[email protected]'],
['dr liam Mc Daid','senior lecturer','academic','MS016','75452','[email protected]'],
['mr derek Woods','senior lecturer','academic','MS134','75380','[email protected]'],
['dr ammar Belatreche','lecturer','academic','MS104','75185','[email protected]'],
['mr michael Callaghan','lecturer','academic','MS132','75771','[email protected]'],
['dr sonya Coleman','lecturer','academic','MS133','75030','[email protected]'],
['dr joan Condell','lecturer','academic','MS131','75024','[email protected]'],
['dr damien Coyle','lecturer','academic','MS103','75170','[email protected]'],
['mr martin Doherty','lecturer','academic','MG121A','75552','[email protected]'],
['dr jim Harkin','lecturer','academic','MS108','75128','[email protected]'],
['dr yuhua Li','lecturer','academic','MS106','75528','[email protected]'],
['dr sandra Moffett','lecturer','academic','MS015','75381','[email protected]'],
['mrs mairin Nicell','lecturer','academic','MG127','75007','[email protected]'],
['mrs maeve Paris','lecturer','academic','MG040','75212','[email protected]'],
['dr jose Santos','lecturer','academic','MG035','75034','[email protected]'],
['dr nH. Siddique','lecturer','academic','MG037','75340','[email protected]'],
['dr zumao Weng','lecturer','academic','MG050','75358','[email protected]'],
['dr shane Wilson','lecturer','academic','MG038','75527','[email protected]'],
['dr caitriona carr','computing and Technical Support','MG121B','75003','[email protected]'],
['mr neil McDonnell','technical Services Supervisor','computing and Technical Support','MS030/MF143','75360','[email protected]'],
['mr paddy McDonough','technical Services Engineer','computing and Technical Support','MS034','75322','[email protected]'],
['mr bernard McGarry','network Assistant','computing and Technical Support','MG132','75644','[email protected]'],
['mr stephen Friel','secretary','clerical staff','MG048','75148','[email protected]'],
['ms emma McLaughlin','secretary','clerical staff','MG048','75153','[email protected]'],
['mrs. brenda Plummer','secretary','clerical staff','MS126','75605','[email protected]'],
['miss paula Sheerin','secretary','clerical staff','MS111','75616','[email protected]'],
['mrs michelle Stewart','secretary','clerical staff','MG048','75382','[email protected]']]
matches = []
criterion = input ("please enter search criterion: ")
criterion = criterion.lower()
for person in staff:
for characteristic in person:
if characteristic in person:
if criterion in characteristic:
matches.append(person)
break
if len(matches) == 0:
print("No Match")
else:
print("POSITION |||DESIGNATION ||| EXT & ROOM NO||| NAME & EMAIL")
for i in matches:
print (i[1].title(),': ',i[2].title(),':',i[3].upper()+ i[4],':',i[0].title(), i[5].title())`
这是香港专业教育学院想出了这么远,它似乎工作,在那里你会作出改善?
数据集的格式是什么?你能提供一个样本入口吗?另外,你到目前为止尝试过什么? – Taymon 2012-03-21 19:26:18