I currently have 9 arrays in python which i am bubblesorting separately depending on the score. how can I make it smaller? (using a record of arrays) -
my current code below, appreciated. works job in many lines of code. there 9 arrays , them record of arrays. not know how go doing this. please post examples of going this.
placement = [1, 2 ,3 ,4 ,5] grade = ["a", "c", "e", "d", "b"] score = [50, 20, 13, 21, 31] music = ["song1", "song2", "song3", "song4", "song5"] maxcombo = [1, 2 ,3 ,4 ,5] perfect = [1, 2 ,3 ,4 ,5] great = [1, 2 ,3 ,4 ,5] = [1, 2 ,3 ,4 ,5] miss = [1, 2 ,3 ,4 ,5] passnum in range(len(score)-1,0,-1): in range(passnum): if score[i]<score[i+1]: temporaryscore = score[i] #stores score temporarygrade = grade[i] #stores grade temporarymusic = music[i] #stores music temporarymaxcombo = maxcombo[i] #stores maxcombo temporaryperfect = perfect[i] #stores perfect temporarygreat = great[i] #stores great temporarygood = good[i] #stores temporarymiss = miss[i] #stores miss score[i] = score[i+1] #swaps score grade[i] = grade[i+1] #swaps grade music[i] = music[i+1] #swaps music maxcombo[i] = maxcombo[i+1] #swaps maxcombo perfect[i] = perfect[i+1] #swaps perfect great[i] = perfect[i+1] #swaps perfect good[i] = good[i+1] #swaps miss[i] = miss[i+1] #swaps miss score[i+1] = temporaryscore #stores score grade[i+1] = temporarygrade #stores grade music[i+1] = temporarymusic #stores music maxcombo[i+1] = temporarymaxcombo #stores maxcombo perfect[i+1] = temporaryperfect #stores perfect great[i+1] = temporarygreat #stores great good[i+1] = temporarygood #stores miss[i+1] = temporarymiss #stores miss
good data structure allows collapse necessary code nothing, see simplified example:
import operator data = [ {"grade": "c", "score": 20}, {"grade": "e", "score": 13}, {"grade": "a", "score": 50}, ] print sorted(data, key=operator.itemgetter("score"), reverse=true)
Comments
Post a Comment