I have a data structure consisting of a list of tags
and weights
pairs, like so:
tags = [['male vocalists', 4], ['Lo-Fi', 2], ['pop underground', 2], ['pop', 16], ['power pop', 99], ['post rock', 2], ['alternative', 59], ['electronic', 2], ['classic rock', 2], ['alternative rock', 14], ['pop rock', 2], ['baroque pop', 2], ['powerpop', 4], ['melodic', 2], ['seen live', 62], ['Bellshill', 3], ['singer-songwriter', 2], ['Favourites', 2], ['Teenage Fanclub', 4], ['emo', 2], ['glasgow', 12], ['Scottish', 73], ['indie pop', 27], ['indie', 100], ['00s', 3], ['new wave', 3], ['rap', 2], ['ambient', 2], ['brit pop', 2], ['90s', 14], ['britpop', 26], ['indie rock', 68], ['electronica', 2], ['shoegaze', 5], ['scotland', 11], ['post-punk', 3], ['Alt-country', 2], ['80s', 3], ['jangle pop', 7], ['guitar pop', 4], ['Pop-Rock', 2], ['rock', 31], ['favorites', 2], ['creation records', 3], ['All', 2], ['punk', 3], ['scottish pop', 2], ['british', 17], ['scottish indie', 2], ['slowcore', 2], ['UK', 6], ['jangly', 2]]
I know I can get tag with the highest value with:
top = max(tags, key=lambda x:x[1])[0]
which yields indie
, correctly.
but how do I get N highest values, say, 5?