Python script for configuring wifi hot spots on FreeBSD

Oliver Fromme olli at
Wed Aug 20 17:18:07 UTC 2008

Andrew Gould wrote:
 > [...]
 > 2. I store data in Python dictionaries.  When I display the
 > dictionaries, the numbered options are not in order and I can't
 > figure out how to sort them.  This appears to be a cosmetic
 > issue only; but it still bothers me.

Python dictionaries aren't ordered.  If you need to
retrieve the items of a dictionary in a particular
order, there are several ways to do that.  For example,
you can use the keys() method to get a list of the
keys in the dictionary, and then apply the sort()
method or the sorted() function to that list:

    my_dict = {"foo": 42, "bar": 17, "baz": 83, "hurz": 55}

    for key in sorted(my_dict.keys()):
        print key, my_dict[key]


    for key, value in sorted(my_dict.items()):
        print key, value

 > I have attached the script -- it is only 4KB.

I didn't see it.  Maybe the mailing list software
removed it.  I suggest you upload it somewhere and
tell us the URL.

Best regards

Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:

"Emacs ist für mich kein Editor. Für mich ist das genau das gleiche, als
wenn ich nach einem Fahrrad (für die Sonntagbrötchen) frage und einen
pangalaktischen Raumkreuzer mit 10 km Gesamtlänge bekomme. Ich weiß nicht,
was ich damit soll." -- Frank Klemm, de.comp.os.unix.discussion

More information about the freebsd-questions mailing list