from collections import namedtuple
Student = namedtuple('Student', 'name gender score')
names = ['ni', 'wo', 'ta']
gender = ['F', 'M', 'F']
scores = [100, 0, 50]
students = [Student(*info) for info in zip(names, gender, scores)]
students[0]
# [Student(name='ni', gender='F', score=100), Student(name='wo', gender='M', score=0), Student(name='ta', gender='F', score=50)]
students[0]._asdict() # OrderedDict([('name', 'ni'), ('gender', 'F'), ('score', 100)])
最后
以上就是尊敬龙猫最近收集整理的关于下列关于python字典变量的定义中错误的是_问一下如何将python3中的字典名字定义为变量?...的全部内容,更多相关下列关于python字典变量内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复