Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Code Samples

169 views
unlisted
ubuntu2204
#INCIDENT SORTING #assign every incident value a column ID, sort it by frequency < greatest least>, and preserve the original column values #incidence table I=[5,3,2,1,0,1,1,7,8] #incidence table with ID, written as (Incidence, ID) #ID is identified as the column number, beginning at 1 #type of col_id is LIST col_id=list(enumerate(I,1)) #ok this is how the list works, its a TUPLE of (INCIDENCE, col# starting at 0 bc cs ppl are evil) #this is how you extract the fuckers, the first coordinate gives you the col ID which for now matches with its order as well, coordinate 2 gives you the inc value #ex: if you do col_id[0][0], it'll spit out "1". if you do [O][1], it'll spit out [5], because the first spot in the big list is (1,5). it's annoying bc the 0]0] command enumerates at 0, whereas i and the rest of civilized humanity enumerates at 1 but whatevs inc_sort=sorted(col_id, key=lambda x: x[1], reverse=True) print ('This is the original ordered pair, written as "column, inc":') print(col_id) print('And this is sorted by frequency:') print(inc_sort)
This is the original ordered pair, written as "column, inc": [(1, 5), (2, 3), (3, 2), (4, 1), (5, 0), (6, 1), (7, 1), (8, 7), (9, 8)] And this is sorted by frequency: [(9, 8), (8, 7), (1, 5), (2, 3), (3, 2), (4, 1), (6, 1), (7, 1), (5, 0)]