Hi Richa,
I'm not particularly versed in this area of the code, but it looks
like the list method creates a new BucketListResultSet object from the
current bucket (based on your prefix and delimiter).
The BucketListResultSet
(boto.s3.bucketlistresultset.BucketListResultSet) object continues to
call the bucket's get_all_keys method (which is deprecated, so it's
not recommended that you use that directly) until the result set is no
longer truncated (ie, the last "page" of the result set).
Put simply, it appears that the order of the results is really
determined by Amazon's returned result set on each page of results.
That is, the results you get back are in exactly the order that Amazon
returns them in a set of pages of results.
That said, if you need them sorted in a particular way, you can
iterate through all of the keys in the list, store them locally in a
list, and then sort that any way you want. I think the idea behind an
iterator was to avoid holding (possibly) enormous lists of keys
locally when most commonly the list() method is for iterating through
the keys to find the one you want.
Hope that answers your question,
JJ