Sorting lexicographically?

I am working on integration with the Photobucket API, and I came across this in api docs :

"Sorting parameters by name lexographically [sic] (byte order, standard sorting, not natural or random insensitive). If the parameters are the same name, then sorting by value."

What does it mean? How do I sort something lexicographically? byte order?

The rest of their documents have been in order so far, but (for me) it seems that this line has additional explanations. Unfortunately, this was not.

Anyway, I am writing an application in Python (it will eventually become a Django application) if you want to recommend special modules that will handle this sorting for me ^ _ ^

+7
python sorting api
source share
4 answers

The word must be "lexicographical"

http://www.thefreedictionary.com/Lexicographic

Word order. Using letters that appear in lines.

As they suggest, do not stack upper and lower case together. Just use the built-in Python list.sort () method.

+6
source share

I think lexicography here is an β€œalias” for ascii sorting?

 Lexicographic natural  
 z1.doc z1.doc    
 z10.doc z2.doc    
 z100.doc z3.doc    
 z101.doc z4.doc    
 z102.doc z5.doc    
 z11.doc z6.doc    
 z12.doc z7.doc    
 z13.doc z8.doc    
 z14.doc z9.doc     
 z15.doc z10.doc    
 z16.doc z11.doc    
 z17.doc z12.doc    
 z18.doc z13.doc     
 z19.doc z14.doc     
 z2.doc z15.doc    
 z20.doc z16.doc    
 z3.doc z17.doc    
 z4.doc z18.doc    
 z5.doc z19.doc    
 z6.doc z20.doc    
 z7.doc z100.doc    
 z8.doc z101.doc    
 z9.doc z102.doc    
+8
source share

This is similar to the Facebook API - the query string should be normalized before generating the signature hash.

You probably have a dictionary of options like:

params = { 'consumer_key': "....", 'consumer_secret': "....", 'timestamp': ..., ... } 

Create a query string as follows:

 urllib.urlencode(sorted(params.items())) 

params.items() returns the keys and values ​​of the dictionary as a list, sorted() sorts the list, and urllib.urlencode() combines them into one line during escaping.

+4
source share

A few more quotes from the section:

2 Create a base line:

Normalize parameters:

  • Add the special OAuth parameters for this request to the input parameters, including:

     oauth_consumer_key = <consumer_key> oauth_timestamp = <timestamp> oauth_nonce = <nonce> oauth_version = <version> oauth_signature_method = <signature_method> 
  • Sort parameters by name lexographically [sic] (byte order, standard sort, not natural or case insensitive). If the parameters have the same name, then sort by value.

  • Encode parameter values, as in RFC3986 Section 2 (i.e. urlencode). Create a parameter string (). This is the same format as HTTP 'postdata' or 'querystring', that is, each parameter represented as name = value, divided by &. For example, a=1&b=2&c=hello%20there&c=something%20else

I think they say the parameters should be displayed in sorted order - oauth_consumer_key to oauth_nonce to ...

+1
source share

All Articles