More with 'for' function confusion


Hello all,
I'm currently on "More with 'for'" exercise and I'm a little confused on the example given on the left side...
The description below is stating that it places the strings into alphabetical order, but I don't see how it did that? There is nothing specific.

Does the ".sort()" automatically order it alphabetical order or am I overlooking something?

Replace this line with your code. 

animals = ["cat", "ant", "bat"]

for animal in animals:
    print animal

1. First, we create a list called animals with three strings. The strings are not in alphabetical order.
2. Then, we sort animals into alphabetical order. Note that .sort() modifies the list rather than returning a new list.
3. Then, for each item in animals, we print that item out as "ant", "bat", "cat" on their own line each.


later, we can write our own methods. Currently, who-ever wrote .sort() implemented it in such a way, that entries are sorted alphabetic

You can always check external documentation to see if you can find out/understand how this sorting algorithm works (python itself has extensive documentation)


Thanks for the quick reply! I appreciate the insight.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.