Python for循环生成列表的实例
一般Pythonfor语句前不加语句,但我在机器学习实战中看到了这两条语句:
featList=[example[i]forexampleindataSet] classList=[example[-1]forexampleindataSet]
多方研究和询问,得到如下解释:
语句featList=[example[i]forexampleindataSet]作用为:
将dataSet中的数据按行依次放入example中,然后取得example中的example[i]元素,放入列表featList中
语句classList=[example[-1]forexampleindataSet]作用为:
将dataSet中的数据按行依次放入example中,然后取得example中的example[-1]元素,放入列表classList中
总而言之,类似上述两种for循环形式可以很方便地用来创建列表,如下例:
list_0=[x*xforxinrange(5)] print(list_0) #输出: #[0,1,4,9,16]
以上这篇Pythonfor循环生成列表的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下