【发布时间】:2020-12-23 04:10:46
【问题描述】:
我想根据现有列表 (arr_0) 获取汽车品牌列表 (arr_1)。这是我的代码:
class Keywords:
def __init__(self):
self.brand = ["kia", "hyundai", "mitsubishi", "honda", "toyota", "ford", "nissan", "suzuki", "vinfast", "mazda"]
def classifyOldKeywords(self, arr_0, type):
arr_copy = []
arr_copy = [arr_0[i] for i in range(len(arr_0))]
arr_for_type = []
[arr_for_type.insert(0, arr_copy.pop(i)) for i in range(len(arr_copy)-1, -1, -1) if (arr_copy[i].lower() in type)]
return arr_for_type
arr_0 = ['VinFast', 'Lux A', 'VinFast', 'Lux A', 'VinFast', 'VinFast', 'Lux A', 'VinFast', 'VinFast', 'Lux A', 'VinFast', 'Lux A', 'VinFast', 'sedan', 'VinFast', 'VinFast', 'Fadil', 'Lux A', 'Lux SA', 'Lux A']
arr_1 = Keywords().classifyOldKeywords(arr_0, Keywords().brand)
print(arr_1)
它返回如下错误:
Traceback (most recent call last):
File "final.py", line 80, in <module>
arr_copy = [arr_0[i] for i in range(len(arr_0))]
TypeError: 'list' object is not callable
感谢您的帮助。
【问题讨论】:
-
正如在另一个问题下的评论中已经说明的那样,这肯定是因为
len或range之前已用作列表的名称。由于没有相关代码,我们无法提供更多信息。