Updating a dictionary in python

I’ve been stuck on this question for quite sometime and just can’t figure it out. I just want to be able to understand what I’m missing and why it’s needed. What I need to do is make a function which adds each given key/value pair to the dictionary. The argument key_value_pairs will be a list … Read more

How to condense if/else into one line in Python?

Possible Duplicate:Python Ternary OperatorPutting a simple if-then statement on one line Is there a way to compress an if/else statement to one line in Python?I oftentimes see all sorts of shortcuts and suspect it can apply here too.

Python: finding an element in a list [duplicate]

The best way is probably to use the list method .index. For the objects in the list, you can do something like: with any special processing you need. You can also use a for/in statement with enumerate(arr) Example of finding the index of an item that has value > 100. Source

Where does pip install its packages?

pip when used with virtualenv will generally install packages in the path <virtualenv_name>/lib/<python_ver>/site-packages. For example, I created a test virtualenv named venv_test with Python 2.7, and the django folder is in venv_test/lib/python2.7/site-packages/django.