Date: Wed, 20 Aug 2008 19:18:03 +0200 (CEST) From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-questions@FreeBSD.ORG, andrewlylegould@gmail.com Subject: Re: Python script for configuring wifi hot spots on FreeBSD Message-ID: <200808201718.m7KHI3SJ051087@lurza.secnetix.de> In-Reply-To: <d356c5630808200844n66270c3ep251e2e38eb777141@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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] Or: 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 -- 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: http://www.secnetix.de/bsd "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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808201718.m7KHI3SJ051087>