我正在尝试从另一个列表中子集一个列表,但我得到一个TypeError.
a = ('one', 'two', 'two', 'three', 'four', 'five', 'three', 'three', 'eight', 'nine', 'ten')
a = list(a)
b = ('two', 'three', 'eight', 'nine')
b = list(b)
c = [a[i] for i in b] # subsets list a for what's in list b
返回:
TypeError:列表索引必须是整数或切片,而不是 str
我在找什么:
print(a)
('two', 'two', 'three', 'three', 'three', 'eight', 'nine')
互换的青春
撒科打诨
相关分类