我有這個作爲一個家庭作業問題,並不知道我應該如何去做。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