Python-如何从列表中的字典位置获得键的值
如果我有以下坐标列表:
coordinateStop = [{'x':450,'y':0},{'x':630,'y':-200},{'x'' :450,'y':200},{'x':-450,'y':0},{'x':-630,'y':200},{'x':450,'y' :-200},{'x':-270,'y':-200},{'x':270,'y':-200},{'x':-630,'y':-200 }]
在列表的第一个位置,在本例450中,我将如何在字典中获取或打印字典的键'x'值?
提前致谢。
If i have a list of coordinates such as follows:
coordinatestop = [{'x': 450, 'y': 0}, {'x': 630, 'y': -200}, {'x': 450, 'y': 200}, {'x': -450, 'y': 0}, {'x': -630, 'y': 200}, {'x': 450, 'y': -200}, {'x': -270, 'y': -200}, {'x': 270, 'y': -200}, {'x': -630, 'y': -200}]
How would i go about getting or printing the value for the key 'x' of the dictionary in the first position of the list, in this case 450?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的列表包含字典,因此调用任何列表的元素与调用字典相同:
因此,您可以将任何列表元素称为字典:
- >首先编写列表索引以调用字典,然后写词典的键以获取其值。
As your list contains dictionaries, calling any list's element is the same as calling a dictionary:
So you can refer to any list element as a dictionary:
--> First write the list index to call the dictionary, then the key of the dictionary to get its value.