[英]List, dictionary, and tuple values
a=[{"a":30},{"c":("a","=","c")}]
I need values of "c"
.我需要"c"
值。
for x in a[1].values():
for j in x:
print(j, end=" ")
This is my solution but if you have any other short solution for this then tell me.这是我的解决方案,但如果您对此有任何其他简短的解决方案,请告诉我。
You could simply say你可以简单地说
for element in a[1]['c']:
print(element,end=" ")
>>> print(' '.join(*a[1].values())) a = c
如果您只需要打印值,您可以将元组作为参数解包来print
:
print(*a[1]['c'])
The same result can be achieved with a comprehension :通过理解可以实现相同的结果:
>>> a=[{"a":30},{"c":("a","=","c")}]
>>> print(*(_ for _ in a[1]['c']))
a = c
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.