在我的Python应用程序中,我有以下几行代码:
for index, codec in enumerate(codecs):
for audio in filter(lambda x: x['hls']['codec_name'] == codec, job['audio']):
audio['hls']['group_id'].append(index)
如果索引之前还没有被追加,我怎么才能触发append语句?
提前感谢
在我的Python应用程序中,我有以下几行代码:
for index, codec in enumerate(codecs):
for audio in filter(lambda x: x['hls']['codec_name'] == codec, job['audio']):
audio['hls']['group_id'].append(index)
如果索引之前还没有被追加,我怎么才能触发append语句?
提前感谢
只需测试if
您的索引not in
您的列表:
for index, codec in enumerate(codecs):
for audio in filter(lambda x: x['hls']['codec_name'] == codec, job['audio']):
if index not in audio['hls']['group_id']:
audio['hls']['group_id'].append(index)