Em có 1 đoạn code như dưới đây: (được trích từ Learn Python the Hard Way - Ex 25)
def break_words(stuff):
words = stuff.split(' ')
return words
def sort_words(words):
return sorted(words)
def print_first_word(words):
word = words.pop(0)
print word
def print_last_word(words):
word = words.pop(-1)
print word
def sort_sentence(sentence):
words = break_words(sentence)
return sort_words(words)
def print_first_and_last(sentence):
words = break_words(sentence)
print_first_word(words)
print_last_word(words)
def print_first_and_last_sorted(sentence):
words = sort_sentence(sentence)
Với sentence = “All good things come to those who wait”
Theo như em hiểu thì khi chạy hàm def cuối cùng của đoạn code này, tức là:
def print_first_and_last_sorted(sentence):
words = sort_sentence(sentence)
thì các từ trong tập hợp của biến words sẽ được sắp xếp theo thứ tự. Tuy nhiên sau đó em in biến words ra thì thấy các từ trong biến này vẫn chưa được sắp xếp (Như trong hình). Xin các bác chỉ giáo cho. Em xin chân thành cảm ơn ạ!

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?