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
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))