1 # list element sum 2 sum = reduce (lambda x,y:x+y, mylist)
1 # compare two lists elements for exact consistency 2 if for inch Zip (X, Y)) 3 Do something
1 # sorts the elements of a dictionary by key, output in LIBSVM format 2 Sorted (Dd.keys ()) 3 for inch Sorted (Dd.keys ())] 4 # Print in LIBSVM format
5 Print ' '. Join ([STR (key) +':' for in Sorted (Dd.keys ())])
1 #sorts the elements of a dictionary by value2 #output only the sorted key3Sorted_key = [key forKeyinchSorted (DD, Key=dd.get, reverse=True)]4 #output only the sorted dictionary5Sorted_dict = [(Key, Dd[key]) forKeyinchSorted (DD, Key=dd.get, reverse=True)]6 #print a dictionary in LIBSVM format7 Print ' '. join ([STR (key) +':'+str (Dd[key]) forKeyinchSorted (DD, Key=dd.get, reverse=true)])
1 # get key intersection of dictionaries 2
1 # sort a list of tuples 2 # Sort by the 0th element of a tuple 3 sorted_list = sorted (tuple_list, key=Lambda x:x[0])
1 # convert LIBSVM Format data to Dict object 2 mydict = {x.split (':') [0]:x.split (':' for inch
1 # sort list and return index of list 2 # sorts the list, returning the original subscript value of the ordered element 3 Sorted_index = sorted (range (Len (list)), key=Lambda k:list[k])
Record several list and dict usages for LIBSVM format data