I ran the below code:
names = ["Carol", "Albert", "Ben", "Donna"]
names.append("Eugenia")
print(sorted(names))
and I got:
['Albert', 'Ben', 'Carol', 'Donna', 'Eugenia']
.append should add the element at the end of list, but order of elements got changed, why the result isn’t ['Carol', 'Albert', 'Ben', 'Donna', 'Eugenia']?
>Solution :
After appending "Eugenia", you’re sorting the list before printing (with sorted). Append merely places a new element at the end of the list.