featList = [example[i] for example in dataSet]
classList = [example[-1] for example in dataSet]
将dataSet中的数据先按行依次放入example中,然后取得example中的example[i]元素,放入列表featList中
>>> dataSet
[[1, 1, 'yes'], [1, 1, 'yes'], [1, 0, 'no'], [0, 1, 'no'], [0, 1, 'no']]
>>> i = 0
>>> featList = [example[i] for example in dataSet]
>>> featList
[1, 1, 1, 0, 0]
>>> i = 0
>>> classList = [example[-1] for example in dataSet]
>>> classList
['yes', 'yes', 'no', 'no', 'no']
最后
以上就是活泼保温杯最近收集整理的关于python [example[i] for example in dataSet] 列表for循环的全部内容,更多相关python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复