我将代码放入IDLE并收到错误消息
TypeError:只能将列表(而不是“ int”)连接到列表。
为什么python不接受this.formBuilder.group({
'eventDates': this.formBuilder.group(
{
'startDate': ['someValue']
}, {
validator: syncValidator, // validator for eventDates group
asyncValidator: asyncValidator // async validator for eventDates group
}
)
})
中的索引作为values[index]
?
我该怎么办?
int
答案 0 :(得分:0)
尝试一下:
def repeat_elem (values, index, num_times):
# this function returns a new list in which the element of 'values'
# at position 'index' has been repeated 'num_times' times
return values[:index] + ([values[index]] * num_times) + values[index+1:]
在上面的代码中:
repeat_elem([1, 2, 3], 0, 5)
返回[1, 1, 1, 1, 1, 2, 3]
repeat_elem([1, 2, 3], 1, 5)
返回[1, 2, 2, 2, 2, 2, 3]
repeat_elem([1, 2, 3], 2, 5)
返回[1, 2, 3, 3, 3, 3, 3]