按字典顺序排序?
我正在努力与 Photobucket API 集成,我在他们的 API 文档:
“按名称对参数进行排序 按字典顺序 [原文如此](字节排序, 标准排序,非自然排序或大小写排序 不敏感)。 如果参数有 相同的名称,然后按值排序。”
这是什么意思?我如何按字典顺序对某些内容进行排序?字节排序?
到目前为止,他们的其余文档都没有问题,但是(对我来说)看起来像这样不幸的是,没有进一步的解释,
无论如何,我正在用 Python 编写应用程序(它最终会成为 Django 应用程序),以防您想要推荐特定的模块。帮我处理这样的排序^_^
I am working on integrating with the Photobucket API and I came across this in their api docs:
"Sort the parameters by name
lexographically [sic] (byte ordering, the
standard sorting, not natural or case
insensitive). If the parameters have
the same name, then sort by the value."
What does that mean? How do I sort something lexicographically? byte ordering?
The rest of their docs have been ok so far, but (to me) it seems like this line bears further explanation. Unfortunately there was none to be had.
Anyway, I'm writing the application in Python (it'll eventually become a Django app) in case you want to recommend specific modules that will handle such sorting for me ^_^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这里的字典顺序是ascii排序的“别名”?
I think that here lexicographic is a "alias" for ascii sort?
该单词应按“字典顺序”
http://www.thefreedictionary.com/Lexicography
字典顺序。 使用字符串中出现的字母。
正如他们建议的那样,不要将大写和小写字母折叠在一起。 只需使用 Python 内置的 list.sort() 方法即可。
The word should be "lexicographic"
http://www.thefreedictionary.com/Lexicographic
Dictionary order. Using the letters as they appear in the strings.
As they suggest, don't fold upper- and lower-case together. Just use the Python built-in list.sort() method.
这与 Facebook API 类似——在生成签名哈希之前需要对查询字符串进行规范化。
您可能有一个参数字典,如下所示:
创建查询字符串,如下所示:
params.items()
以列表元组的形式返回字典的键和值,sorted()
> 对列表进行排序,urllib.urlencode()
在转义时将它们连接成单个字符串。This is similar to the Facebook API — the query string needs to be normalized before generating the signature hash.
You probably have a dictionary of parameters like:
Create the query string like so:
params.items()
returns the keys and values of the dictionary as a list tuples,sorted()
sorts the list, andurllib.urlencode()
concatenates them into a single string while escaping.引用该部分的更多内容:
我认为他们是说参数必须按排序顺序出现 -
oauth_consumer_key< /code> 之前
oauth_nonce
之前 ...Quote a bit more from the section:
I think that they are saying that the parameters must appear in the sorted order -
oauth_consumer_key
beforeoauth_nonce
before ...