strcmp for python or how to sort substrings efficiently (without copy) when building a suffix array

后端 未结 4 1747
孤独总比滥情好
孤独总比滥情好 2021-02-06 00:24

Here\'s a very simple way to build an suffix array from a string in python:

def sort_offsets(a, b):
    return cmp(content[a:], content[b:])

content = \"foobar          


        
4条回答
  •  盖世英雄少女心
    2021-02-06 01:01

    The buffer function does not copy the whole string, but creates an object that only references the source string. Using interjay's suggestion, that would be:

    suffix_array.sort(key=lambda a: buffer(content, a))
    

提交回复
热议问题