【问题标题】:Python split list of dict by the value of one of the keysPython 按其中一个键的值拆分 dict 列表
【发布时间】:2021-10-05 18:22:18
【问题描述】:

如果我有这样的字典列表:

[
{'type': 'one', 'other': 'anything'},
{'type': 'one', 'other': 'anything'},
{'type': 'two', 'other': 'anything'},
{'type': 'three', 'other': 'anything'},
{'type': 'four', 'other': 'anything'}
]

等等

获取“类型”的所有唯一值的最佳方法是什么?

【问题讨论】:

标签: python list key unique


【解决方案1】:

如果您只需要获取唯一密钥,只需将其转换为如下集合。

set(_["type"] for _ in YourDataArray)

【讨论】:

  • 我实际上需要 type 的唯一值,您的解决方案有所帮助。谢谢!
猜你喜欢
  • 1970-01-01
  • 2019-04-06
  • 2019-09-22
  • 2013-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多