Skip to content

Tag: python

Multi-level defaultdict with variable depth?

I have a large list like: I want to build a multi-level dict like: I know that if I use recursive defaultdict I can write table[A][B1][C1]=1, table[A][B2]=2, but this works only if I hardcode those insert statement. While parsing the list, I don’t how many []’s I need beforehand to call table[key1…

Why doesn’t Pydev find Django?

I have Django installed. I also have django-admin.py in my python-2.7 folder. I can import django using my Python shell (DreamPie). But I can’t create a new Django project in Pydev. When trying to create a new Pydev Django Project (choosing python2.7 as the interpreter) I receive the following error mes…

Histogram Matplotlib

So I have a little problem. I have a data set in scipy that is already in the histogram format, so I have the center of the bins and the number of events per bin. How can I now plot is as a histogram. I tried just doing but it didn’t like that. Any recommendations? Answer The object-oriented interface i…

How to round each item in a list of floats to 2 decimal places?

I have a list which consists of float values but they’re too detailed to proceed. I know we can shorten them by using the (“%.f” % variable) operator, like: My question is how can I turn a list of values into their rounded equivalents without using an iterator. I’ve tried something, bu…

How to delete an AMI using boto?

(cross posted to boto-users) Given an image ID, how can I delete it using boto? Answer You use the deregister() API. There are a few ways of getting the image id (i.e. you can list all images and search their properties, etc) Here is a code fragment which will delete one of your existing AMIs (assuming it&#82…

How to get MD5 sum of a string using python?

In the Flickr API docs, you need to find the MD5 sum of a string to generate the [api_sig] value. How does one go about generating an MD5 sum from a string? Flickr’s example: string: 000005fab4534d05api_key9a0554259914a86fb9e7eb014e4e5d52permswrite MD5 sum: a02506b31c1cd46c2e0b6380fb94eb3d Answer For Py…

Plot smooth line with PyPlot

I’ve got the following simple script that plots a graph: As it is now, the line goes straight from point to point which looks ok, but could be better in my opinion. What I want is to smooth the line between the points. In Gnuplot I would have plotted with smooth cplines. Is there an easy way to do this