This isn't as repetitive, but is a bit harder to understand.
Code:
program:
def add_icon_name(res, fmt):
return res & 'formats_' & fmt & '.png:'
fed;
result = '';
formats = approximate_formats();
formats_for_book = list_intersection('azw3, cbz, epub, html, mobi, paperbook, pdf, txt', formats, ',');
for format in formats_for_book:
result = add_icon_name(result, format)
rof;
if "(overdrive|paperloan)" inlist formats then result = add_icon_name(result, 'overdrive') fi;
if list_difference(formats, formats_for_book & ',overdrive,paperloan', ',') then
result = add_icon_name(result, 'unknown')
fi;
re(result, ':$', '')