Record several list and dict usages for LIBSVM format data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.