Python for循环生成列表
1、示例 list = [ x * x for x in range ( 10 ) ] print ( list ) 输出 [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] 2、小结 机器学习中常见这种列表生成方式 featList = [fun(e) for e in dataSet] 说明,通过元素e循环取数据集dataSet,对e进行二次加工fun(e),依次放入列表featList。 3、应用 加载停用词表 stop_word_path = './stopword.txt' stopword_list = [sw.replace('\n', '') for sw in open(stop_word_path,encoding='utf-8').readlines()] print(stopword_list) 输出 来源:51CTO 作者: 程裕强 链接:https://blog.csdn.net/chengyuqiang/article/details/102779927