获取第一个元素作为索引以更新列表中的其余元素
Posted
技术标签:
【中文标题】获取第一个元素作为索引以更新列表中的其余元素【英文标题】:Get first element as index to update the rest of the elements within the list 【发布时间】:2021-03-29 23:04:28 【问题描述】:This is my web output using flask
registrant_record = [['1', 'James Dommenick Asaria', 'bluesmooth22@gmail.com', '09057367450', 'reg'], ['2', 'Dominador Sultan', 'princessaming@gmail.com ', '09363319670', 'reg']]
我想在点击更新按钮时获取第一个元素。
【问题讨论】:
【参考方案1】: registrant_record = [['1', 'James Dommenick Asaria', 'bluesmooth22@gmail.com', '09057367450', 'reg'], ['2', 'Dominador Sultan', 'princessaming@gmail.com', '09363319670', 'reg']]
registrant_dict=
for i in registrant_record:
registrant_dict[int(i[0])]=i[1:]
print(registrant_dict[1])
output
['James Dommenick Asaria', 'bluesmooth22@gmail.com', '09057367450', 'reg']
##### if you want just the first name ####
registrant_record = [['1', 'James Dommenick Asaria', 'bluesmooth22@gmail.com', '09057367450', 'reg'], ['2', 'Dominador Sultan', 'princessaming@gmail.com', '09363319670', 'reg']]
registrant_dict=
for i in registrant_record:
# you want to get the first change i[1] or second element i[2]
registrant_dict[int(i[0])]=i[1]
print(registrant_dict[1])
output
['James Dommenick Asaria']
【讨论】:
以上是关于获取第一个元素作为索引以更新列表中的其余元素的主要内容,如果未能解决你的问题,请参考以下文章