小编Tor*_*den的帖子

蟒蛇.使用词典列表进行操作

朋友们,我有一个词典列表:

my_list = 
[
{'oranges':'big','apples':'green'},
{'oranges':'big','apples':'green','bananas':'fresh'},
{'oranges':'big','apples':'red'},
{'oranges':'big','apples':'green','bananas':'rotten'}
]
Run Code Online (Sandbox Code Playgroud)

我想创建一个新的列表,消除部分重复.

在我的情况下,必须删除这本词典:

{'oranges':'big','apples':'green'}
Run Code Online (Sandbox Code Playgroud)

,因为它复制了较长的词典:

{'oranges':'big','apples':'green','bananas':'fresh'}
{'oranges':'big','apples':'green','bananas':'rotten'}
Run Code Online (Sandbox Code Playgroud)

因此,期望的结果:

[
{'oranges':'big','apples':'green','bananas':'fresh'},
{'oranges':'big','apples':'red'},
{'oranges':'big','apples':'green','bananas':'rotten'}
]
Run Code Online (Sandbox Code Playgroud)

怎么做?太感谢了!

python dictionary list

10
推荐指数
2
解决办法
1086
查看次数

将字符串动态转换为列名称.MySQL的

我有两张桌子:itemsorders

items
--------------
id (int) | type_1 (int) | type_2  (int)|

orders
--------------
id (int) | transaction_type enum ('type_1', 'type_2')
Run Code Online (Sandbox Code Playgroud)

基本上,我想做以下事情:

select (select transaction_type from orders where id=1) from items;
Run Code Online (Sandbox Code Playgroud)

所以,问题是string返回的select transaction_type from orders where id=1,不能转换成列名.

mysql

9
推荐指数
2
解决办法
2万
查看次数

如何从字典中的每个值列表中选择一个项目的所有排列?

朋友,基本上,我想采取一个字典:

fruit_dict = {'oranges':['big','small'],'apples':['green','yellow','red']}
Run Code Online (Sandbox Code Playgroud)

并通过在不同键的所有值之间进行所有可能的排列来获得以下字典列表:

output_list = 
[
{'oranges':'big','apples':'green'},
{'oranges':'big','apples':'yellow'},
{'oranges':'big','apples':'red'},
{'oranges':'small','apples':'green'},
{'oranges':'small','apples':'yellow'},
{'oranges':'small','apples':'red'}
]
Run Code Online (Sandbox Code Playgroud)

怎么做?太感谢了!

python dictionary list permutation

1
推荐指数
1
解决办法
222
查看次数

标签 统计

dictionary ×2

list ×2

python ×2

mysql ×1

permutation ×1