如何在python3中获取不断增长的列表的数据

时间:2017-12-05 08:46:16

标签: python-3.x list

有我的清单:

fieldNames = ["Your Firstname","Year of birth", "Month of birth", "Day of   Birth"]
birthValues = []
birthValues = multenterbox(msg, title, fieldNames)
yourName = birthValues[0]
yearBirth = birthValues[1]
 monthBirth = birthValues[2]
dayBirth = birthValues[3]

我可以找到列表的长度:   LEN(FIELDNAMES)

我的问题是我一直在列表中添加值。所以我需要能够自动获取下一个值的东西[4] [5] [6]等...

1 个答案:

答案 0 :(得分:0)

你的意思是你想要一个循环,就像这样?

fieldNames = ["Your Firstname","Year of birth", "Month of birth", "Day of   Birth"]
birthValues = multenterbox(msg, title, fieldNames)
mapping = dict()
for i in range(len(fieldNames)):
    mapping[fieldNames[i]] = birthValues[i]

您可以使用mapping["Your Firstname"]访问birthname。