Py学习  »  Python

基于python中的字符串值从列表中返回特定值

Will James • 5 年前 • 1473 次点击  

我已经从数据库中检索到总统并创建了一个列表。现在,我需要根据用户提供的PNAME检索4位PIN。下面是生成的列表。

['George Bush 6182', 'John Kennedy 5860', 'Barrack Obama 6394', 'Harry Truman 6478', 'Richard Nixon 7155'] 

我试过循环浏览列表,但没有成功。

full_list = []
pName = message[cmd_index + 2]
p_map_snapshot = db_root.child('pMap').get()
p_id = p_map_snapshot[message[cmd_index + 1].lower()]
roster_snapshot = db_root.child('rosters').child(p_id).get()
print (pName)
for prez in roster_snapshot:
    full_list.append((prez['firstName'] + " " + prez['lastName'] + " " + str(prez['pinId'])))
         #LOOP HERE?
              #if pName == ?
#print(full_list)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38178
 
1473 次点击  
文章 [ 1 ]  |  最新文章 5 年前