Py3: Replace map() with a list comprehension

In Python 3, map() returns a map object, which is not JSON-serializable. Use a
list comprehension to fix the issue.

Change-Id: I1e50b5057bdca57fcca8a10882e878f63d102ac8
This commit is contained in:
Cyril Roelandt 2018-12-01 19:46:08 +01:00 committed by Tim Burke
parent 333ae3086f
commit a883adaa69

View File

@ -31,9 +31,8 @@ def create_bucket_list_json(buckets):
:param buckets: a list of tuples (or lists) consist of elements orderd as
name, count, bytes
"""
bucket_list = map(
lambda item: {'name': item[0], 'count': item[1], 'bytes': item[2]},
list(buckets))
bucket_list = [{'name': item[0], 'count': item[1], 'bytes': item[2]}
for item in buckets]
return json.dumps(bucket_list)