python - 列表列表上的 For 循环
问题描述
我有一个包含一些数据的列表列表,我希望能够调用列表列表的内容,但只能调用某些内容,例如:empList[0][0]
,empList[0][1]
。我希望能够对列表中的每个项目执行此操作,然后从列表的该部分调用选定的索引 ex: empList[0][0]
, empList[0][1]
, empList[1][0]
,empList[1][1]
但在 for 循环中。我的参考代码:
empList = [
['51-4678119', 'Issie', 'Scholard', '11 Texas Court', 'Columbia', 'Missouri', '65218', '3', '134386.51', '34', '91.06'],
['68-9609244', 'Jed', 'Netti', '85 Coolidge Terrace', 'San Antonio', 'Texas', '78255', '2', '159648.55', '47', '45.7'],
['47-2771794', 'Galvan', 'Solesbury', '3 Drewry Junction', 'Springfield', 'Illinois', '62794', '2', '91934.89', '39', '47.92']
]
emp = employee(empList[0][0], empList[0][1], empList[0][2], empList[0][3], empList[0][4], empList[0][5], empList[0][6], empList[0][7])
希望这是有道理的。谢谢!
解决方案
如果参数总是按正确的顺序排列,你可以这样做:
employees = [employee(*args) for args in empList]
推荐阅读
- android - 远程服务 - 无法启动服务 Intent U=0 not found
- python - 通过 pip install 使用 gdal 时出现内置轮错误
- jsf - 图像在 p:galeria 中错误地重复
- java - 如何在 Spring Data Couchbase 中使用 CouchbaseTemplate 中的键前缀
- angular - 没有 TranslateService 的提供者
- blueprism - 如何将桌面应用程序中下拉列表的所有元素放入蓝色棱镜中的集合中
- python - 将字母转换为有值的数字
- xamarin - Xamarin Forms iOS 和 Android 非常轻量(细)字体
- c# - 如何在c#中检查一个对象是否没有空属性
- c# - 具体来说,在 Unity 中,await 从字面上返回到“哪里”?