--

Your map example is a bit misleading, because map uses lazy iteration. When you call map, it doesn't immediately do any work, it just creates a lazy iterator the will do the work when you ask it to.

Creating the map doesn't convert any of the strings. That is why it appears to be so fast.

You need to access the elements in the map to cause it to actually calculate the values. For example if you execeute list(upper_list2) that at that point all the strings will get converted. That will take considerably longer than 2e-5 seconds, probably more like the list comprehension.

--

--

Martin McBride
Martin McBride

No responses yet