I haven't used str.format() much before and am wondering how to pass in list values and retrieve a list output with these values passed in.
i.e.
listex = range(0, 101, 25)
baseurl = "https://thisisan{0}example.com".format(*listex)
I'd like a list output like ["https://thisisan0example.com", "https://thisisan25example.com", "https://thisisan50example.com", etc etc]
but with my current code above, I'm only getting "https://thisisan0example.com"
when I run print baseurl
You cannot get your output as shown using a single format. You can use a list-comp
You can use
map
here (if you are using Py3, wrap alist
call),This can then be stored in your variable
baseurl
asThe speed comparision can be done using
timeit
As you can see, the
map
is faster here (Python2) as there is no involvement of alambda