- Sự là em mới học lập trình, nên hỏi câu hơi ngáo bác nào thông não giúp em phát.
- Em thắc mắc cái cơ chế của bọn iter , vd gọi reverse() hay sort() cho đối tượng item xong nó làm việc thế nào mà cuối cùng số 1 với 2 nó lại khác nhau.
import re
st = "- without,hello,bag,world\nThen, the ? output!!!!? should. be:\nbag,hello,without,world???!!! "
item = [word for word in re.split("[,. \-!?:\n]+",st) if word]
#1
item.reverse()
print(1)
print(item,"\n.\n.")
#2
print(2)
print(item.reverse())
Console
1
['world', 'without', 'hello', 'bag', 'be', 'should', 'output', 'the', 'Then', 'world', 'bag', 'hello', 'without']
.
.
2
None

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