- Dictionaries are encoded as a 'd' followed by a list of alternating keys and their corresponding values followed by an 'e'. For example, d3:cow3:moo4:spam4:eggse corresponds to {'cow': 'moo', 'spam': 'eggs'} and d4:spaml1:a1:bee corresponds to {'spam': ['a', 'b']}. Keys must be strings and appear in sorted order (sorted as raw strings, not alphanumerics).
sorted as raw strings, not alphanumerics: 可以翻译为:以原始字符串来排序,而不是按单个字符或数字来进行排序。
个人查了一下资料,发现 raw string : 是python语言的特性,说明
A feature of PythonLanguage. A rawstring is a string literal (prefixed with an r) in which the normal escaping rules have been suspended so that everything is a literal.
For example:
print r"//*/*//**" actually prints "//*/*//**"
This is incredibly useful for writing readable regular expressions or any string literals that will be processed by other escaping systems such as SQL parsers.To work around the backslash plague, you can use what is called a raw string, by prefixing the '...' with the letter r. This tells Python that nothing in this string should be escaped; '/t' is a tab character, but r'/t' is really the backslash character / followed by the letter t. I recommend always using raw strings when dealing with regular expressions, otherwise things get too confusing too quickly (and regular expressions get confusing quickly enough all by themselves).
http://www.faqs.org/docs/diveintopython/dialect_re.html以r为前缀的字符串中的内容是直接输出该内容,内容中是不带任何转义或控制字符的。
个人对sorted as raw strings, not alphanumerics的理解为:
以原始字符串整串字符来进行排序,而不单单是按单个字符或数字。因为原始字符串的比较层面是以整串字符来进行,比如说:如果两个串第一字母相同,就比较第二个字母ASCII的大小,还要,字符串中的内容也还包括了ASCII中的128个字符的比较,而不仅仅限于字符或数字。
e.g :
d5:cowmg4:eggs3:cow3:mooe
解码后输出:
cow => moo
cowmg => eggsd5:+owmg4:eggs3:$ow3:mooe
解码后输出:
$ow => moo
+owmg => eggs
sorted as raw strings, not alphanumerics 的个人理解?
最新推荐文章于 2025-08-15 08:27:29 发布