Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Working with Iterators in Python

Iterator vs Generator

Generator is a special case of Iterator. Generator is easy and convenient to use but at additional cost (memory and speed). If you need performance, use plain iterator (with the help of the itertools module). If you need convenience and concise code, use generator.

Please refer to Python Generator vs Iterator for more detailed discussions.

TeXstudio, Bravo!

I have heard about TeXstudio for a long time. I tried it today on a Debian virtual machine. It works like a charm. I like the preview function a lot. Using inline preview, you can see compiled result while you are typing. It works even with user-defined commands. This is …

Install Python Packages Using pip

PyPi Statistics

You can check download statistics of Python Packages on PYPI at https://pypistats.org/. This is especially helpful if you want to choose from multiple packages.

Prefer pip

pip is preferred over OS tools (e.g., apt-get, yum, wajig, aptitude, etc.) for managing Python packages. If you are …

The set Collection in Python

General Tips and Traps

  1. The set class is implemented based on hash table which means that its elements must be hashable (has methods __hash__ and __eq__). The set class implements the mathematical concepts of set which means that its elements are unordered and does not perserve insertion order of elements. Notice that this is different from the dict class which is also implemented based on hash table but keeps insertion order of elements! The article Why don't Python sets preserve insertion order?

Useful Visual Studio Code Extensions

Places to Find Extensoins

Visual Studio Code Marketplace and Open VSX Registry are 2 places to find VSCode compatible extensions.

Install VSCode Extensions from Command-line

https://stackoverflow.com/questions/34286515/how-to-install-visual-studio-code-extensions-from-command-line/34339780#34339780

Install Code-Server Extensions from Command-line

If you install extension in Dockerfile using root, the extensions are installed …