Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
您可以使用列表理解来执行此操作:
循环在列表上,只需从dict中获取
a
值即可。对于myNewlist2
,只需做同样的事情,但是有2个值:You can use list comprehension to do this:
Loop over the list and just grab the
a
value from the dict. Formynewlist2
, just do the same thing, but with 2 values:像以下内容应该解决问题。请注意,这只会保留
trunc_size
嵌套词典的数字。不是条目a
和b
的特定特定条目。目前尚不清楚需要哪个,但是如果您的词典中的键更改,目前在这个问题上的两个答案都将产生不同的结果。Something like the following should do the trick. Note that this just keeps the
trunc_size
number of nested dictionaries. Not specific to entriesa
andb
. It's unclear which was needed, but both answers currently on this question will yield different results if your keys in your dictionaries change.