First, you don't need to define list length at the beginning in
general case:
您可以简单地执行以下操作:
#Just for example
new_list=[]
for i in map(chr,range(97,101)):
new_list.append(i)
print(new_list)
输出:
['a', 'b', 'c', 'd']
Yes you need to define a empty list when you have another list for
index items like this:
matching_words=[None]*10
index_list=[4,3,1,2]
for i in zip(list(map(chr,range(97,101))),index_list):
matching_words.insert(i[1],i[0])
print(matching_words)
您应该从一个空列表开始,并向其中添加以下项目:
另外,为了让您了解
remove
方法:样本输出:
当你需要定义列表长度和不需要的时候,我想解释一些事情
您可以简单地执行以下操作:
输出:
输出:
在这个程序中,我们必须按索引列表显示整数的顺序插入chracter,所以如果我们不在之前定义list,那么正如你所看到的,我们在索引4处插入第一个chr,而索引4不在那里
在您的情况下,如果您有第二种情况,请尝试此操作以删除其余情况:
否则,如果你是第一个病例
相关问题 更多 >
编程相关推荐