Posts

Showing posts with the label Python

[Python] zip(*[iter(s)]*n)

zip(*[iter(s)]*n) 1. A better syntax for explanation is that: zip(*[iter(s)]*n) is same as zip(*([iter(s)] * n)) 2. iter() is an iterator over a sequence (in this case, s). 3. [iter(s)] * n <==> [iter(s), iter(s), ... <n times>] : creates an array of iterators 4. zip() method takes a input parameter in form of zip(*args), meaning it can take zip(x), zip(x,x), zip(x,x,x) and so forth. 5. Combining this, we are just doing: zip(iter(s), iter(s), <repeated n times>) Resources:  https://stackoverflow.com/questions/2233204/how-does-zipitersn-work-in-python

[Python] Python Equivalent of npm or rubygem

If you don't already have virtualenv installed, then install it globally with:  pip install virtualenv (or pip3 - for python3) Each Python project should have its own virtualenv installation. It's easy to set one up, just cd to your project's root and: python3 -m virtualenv env # creates env folder with everything you need Activate virtualenv:  source env/bin/activate Deactivate virtualenv: deactivate Now, any interaction with pip is contained within your project. Run  pip install package_name==version  for each of your dependencies. They are installed in ./env/lib/python3.x/site-packages/ When you want to save your project's dependencies to a file, run: pip freeze > requirements.txt You actually don't need -l or --local if you're in an activated project-specific virtualenv (which you should be). Now, when you want to install your dependencies from requirements.txt, set up your virtualenv, and run: pip install -r requirements.txt T...