Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中向列表中输入多个重复值的方法_Python_Python 3.x_Python 2.7 - Fatal编程技术网

在Python中向列表中输入多个重复值的方法

在Python中向列表中输入多个重复值的方法,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,我试图生成多个重复值并将其输入到一个列表中,如下所示 look_back_timeseries_to_supervised_learning = 6 print(('None,'*(look_back_timeseries_to_supervised_learning-1))[:-1].split(',')) 这给了我 ['None', 'None', 'None', 'None', 'None'] 我怎么才能 [None, None, None, None, None] 这就是你想要的

我试图生成多个重复值并将其输入到一个列表中,如下所示

look_back_timeseries_to_supervised_learning = 6
print(('None,'*(look_back_timeseries_to_supervised_learning-1))[:-1].split(','))
这给了我

['None', 'None', 'None', 'None', 'None'] 
我怎么才能

[None, None, None, None, None]
这就是你想要的吗?(更改包含所需非编号的任何变量的文件)

如果您有:

l = ['None', 'None', 'None', 'None', 'None']
您可以使用以下方法更改列表:

l = [None if x == 'None' else x for x in l]

只需做[无]*回顾一下\u timeseries\u到\u监督\u学习谢谢,我是Python的初学者!:D
l = [None if x == 'None' else x for x in l]