result = []
for file in files:
if not file['quality'] == 'hls':
result.append({
f"{file['height']}p{file['fps']}": {
'link': file['link'],
'type': file['type'],
'size': file['size']
}
})
else:
result.append({
file['quality']: {
'link': file['link'],
'type': file['type'],
'size': file['size']
}
})
return result
Возможно
def serialize_file(file): return { 'link': file['link'], 'type': file['type'], 'size': file['size'] }
Key = key1 if quality == lhs else key2; result.append(key: {..})
ну как минимум так def parse_files(files): result = [] for file in files: key = 'hls' if file['quality'] == 'hls' else f"{file['height']}p{file['fps']}" result.append({ key: { 'link': file['link'], 'type': file['type'], 'size': file['size'] } }) return result
def parse_files(files): result = [] for file in files: result.append({ f"{file['height']}p{file['fps']}" if not file['quality'] == 'hls' else file['quality']: { 'link': file['link'], 'type': file['type'], 'size': file['size'] } }) return result
Обсуждают сегодня