Question

Does anyone know how to get reversed bucket list.

bucketList = self.bucket.list(PREFIX)
bucketList.reverse()

does not work.

Thanks, Ron.

Was it helpful?

Solution

The reason that you can't do a reverse of bucket.list() is because that method actually returns a generator rather than the actual list. This is much more efficient and also allows boto to handle all of the paging of results behind the scenes.

If you really want to reverse it you could collect all of the elements in a list and then reverse that:

objs = [obj for obj in self.bucket.list(PREFIX)]
objs.reverse()

but if there are a lot of objects in the bucket this will be very inefficient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top