Now, this code can be simplified using comprehensions. But comprehensions only work with lists, dictionaries, and sets, whereas the lenses library can work with arbitrary python objects. Here's an example that
the first variant could be the fastest as it avoids lookup overhead to get the constructor and byte code execution for the inner items. However, the wrapped equivalent might eventually be faster on CPython 3. On
Now, this code can be simplified using comprehensions. But comprehensions only work with lists, dictionaries, and sets, whereas the lenses library can work with arbitrary python objects. Here's an example that shows off the full power of this library: ...