在即將到來的問題中有一個遞歸選擇排序需要完成。遞歸選擇排序python
def selsort(l):
"""
sorts l in-place.
PRE: l is a list.
POST: l is a sorted list with the same elements; no return value.
"""
l1 = list("sloppy joe's hamburger place")
vl1 = l1
print l1 # should be: """['s', 'l', 'o', 'p', 'p', 'y', ' ', 'j', 'o', 'e', "'", 's', ' ', 'h', 'a', 'm', 'b', 'u', 'r', 'g', 'e', 'r', ' ', 'p', 'l', 'a', 'c', 'e']"""
ret = selsort(l1)
print l1 # should be """[' ', ' ', ' ', "'", 'a', 'a', 'b', 'c', 'e', 'e', 'e', 'g', 'h', 'j', 'l', 'l', 'm', 'o', 'o', 'p', 'p', 'p', 'r', 'r', 's', 's', 'u', 'y']"""
print vl1 # should be """[' ', ' ', ' ', "'", 'a', 'a', 'b', 'c', 'e', 'e', 'e', 'g', 'h', 'j', 'l', 'l', 'm', 'o', 'o', 'p', 'p', 'p', 'r', 'r', 's', 's', 'u', 'y']"""
print ret # should be "None"
我知道如何使用關鍵→ l.sort(key=str.lower)
得到這個。但是這個問題想要我提取最大元素,而不是最小值,只能將其提交給遞歸排序的子列表。
如果我能得到任何幫助,我將不勝感激。
請注意,您可以通過將行縮進四個空格來將行格式化爲代碼。編輯器工具欄中的「101 \ n010」按鈕可以爲您做到這一點。您可以使用底部的編輯鏈接編輯您的問題,並現在格式化示例代碼。單擊編輯器工具欄中的橙色問號以獲取更多信息和格式化提示。 – outis 2010-12-03 02:55:43