在下面的代码行中,我正在尝试处理track_ids,set这是不允许的indexing.
track_name = sp.track(track_ids[i])['name']
我如何转换track_ids成一个list所以我能够索引它?
编辑:这是完整的功能:
def filterBelowThreshold(product, filter_name, track_ids, values, 
    xsongs, threshold):
    print product.upper(), 'PLAYLIST:'
    for i, x in enumerate(values):
        if x < threshold:
            track_name = sp.track(track_ids[i])['name']
            #append minding foreign track names
            xsongs.add(track_name.encode("utf-8"))
            print product.upper(),'-', "{} = {}".format(track_name.encode("utf-8"), x), filter_name
你可以通过调用函数将a转换set为a .listlist(track_ids)
请注意,在这个新的列表中的元素不会有一个有意义的顺序,所以访问它就像你正在与做i,列举了另一个列表索引是不正确的,假定你认为在元素values和track_ids有些相关.
但是,如果你真的想要values和track_ids配对(可能是随机配对),你可以尝试这种更简洁的方式:
for val, track_id in zip(values,list(track_ids)):