我有
{key1:value1, key2:value2, etc}
我希望它变成:
[key1,value1,key2,value2] , if certain keys match certain criteria.
我怎样才能尽可能地用 Python 方式完成它?
谢谢!
最佳答案
这应该可以解决问题:
[y for x in dict.items() for y in x]
例如:
dict = {'one': 1, 'two': 2}
print([y for x in dict.items() for y in x])
这将打印:
['two', 2, 'one', 1]
关于python - 将字典转换为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11351874/