In my Python application, I have the following lines:
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)
How can I only trigger the append statement if the index hasn’t been already appended previously?
Advertisement
Answer
Simply test if your index not in your list:
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)
 
						