Looking for shrunk list compression and fewer loops and memory usage, is there a way to reduce two loops to build end paths by turning them into a single comprehesion list?
def build_paths(domains):
http_paths = ["http://%s" % d for d in domains]
https_paths = ["https://%s" % d for d in domains]
paths = []
paths.extend(http_paths)
paths.extend(https_paths)
return paths
In this case, the expected result is an optimized list count, decreasing of the three lists of links ( http_paths
, https_paths
, paths
) in one single row, for example, the following exemplary structure:
def build_paths(domains):
return [<reduced list comprehesion> for d in domains]
In both cases, the following test is performed:
domains = ["www.ippssus.com",
"www.example.com",
"www.mararao.com"]
print(build_paths(domains))
Expected result, independent of list order:
< ['http://www.ippssus.com', 'http://www.example.com', 'http://www.tetsest.com', 'https://www.ippssus.com', 'https://www.example.com', 'https://www.tetsest.com']
apast source
share