小编Jas*_*e N的帖子

从嵌套列表中获取一组唯一值

我有这个嵌套列表 X_train

X_train = [['sunny', 'hot', 'high', 'FALSE'],
 ['sunny', 'hot', 'high', 'TRUE'],
 ['overcast', 'hot', 'high', 'FALSE'],
 ['rainy', 'mild', 'high', 'FALSE'],
 ['rainy', 'cool', 'normal', 'FALSE'],
 ['rainy', 'cool', 'normal', 'TRUE'],
 ['overcast', 'cool', 'normal', 'TRUE'],
 ['sunny', 'mild', 'high', 'FALSE'],
 ['sunny', 'cool', 'normal', 'FALSE'],
 ['rainy', 'mild', 'normal', 'FALSE'],
 ['sunny', 'mild', 'normal', 'TRUE'],
 ['overcast', 'mild', 'high', 'TRUE'],
 ['overcast', 'hot', 'normal', 'FALSE'],
 ['rainy', 'mild', 'high', 'TRUE']]
Run Code Online (Sandbox Code Playgroud)

我想生成一个列表,其中的第 n 行X_train包含X_train. 所以预期的输出应该是:

[{'overcast', 'rainy', 'sunny'},
 {'cool', 'hot', 'mild'},
 {'high', 'normal'},
 {'FALSE', 'TRUE'}]
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

questions=[] …
Run Code Online (Sandbox Code Playgroud)

python set

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

标签 统计

python ×1

set ×1